如何侦听消息队列(MSMQ)。当消息队列中有消息出来时就显示在文本框中

jiangwk23 2009-04-10 02:37:23
如何侦听消息队列(MSMQ)。当消息队列中有消息出来时就显示在文本框中

如题~~急
...全文
196 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuliunumberone 2011-11-17
  • 打赏
  • 举报
回复
我是根据楼上的做法做的,但是就是接收不到body怎么回事呢?
贪玩的老鼠 2009-08-19
  • 打赏
  • 举报
回复
有两种方法
1. 使用消息队列的触发器就.
做个消息组件给消息触发器触发调用
2. 使用消息接收回调函数.
四楼给出了代码!!
yuxianye1 2009-04-11
  • 打赏
  • 举报
回复

using System;
using System.Messaging;

public class QueueExample
{
public static void Main()
{
// Create a non-transactional queue on the local computer.
// Note that the queue might not be immediately accessible, and
// therefore this example might throw an exception of type
// System.Messaging.MessageQueueException when trying to send a
// message to the newly created queue.
CreateQueue(".\\exampleQueue", false);

// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");

// Add an event handler for the ReceiveCompleted event.
queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MyReceiveCompleted);

// Send a message to the queue.
queue.Send("Example Message");

// Begin the asynchronous receive operation.
queue.BeginReceive(TimeSpan.FromSeconds(10.0));

// Simulate doing other work on the current thread.
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10.0));

return;
}

// Creates a new queue.
public static void CreateQueue(string queuePath, bool transactional)
{
if(!MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath, transactional);
}
else
{
Console.WriteLine(queuePath + " already exists.");
}
}

// Provides an event handler for the ReceiveCompleted event.
private static void MyReceiveCompleted(Object source,
ReceiveCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue queue = (MessageQueue)source;

// End the asynchronous receive operation.
Message msg = queue.EndReceive(asyncResult.AsyncResult);

// Display the message information on the screen.
Console.WriteLine("Message body: {0}", (string)msg.Body);
}
}


yuxianye1 2009-04-11
  • 打赏
  • 举报
回复
BeginReceive 事件处理
wuyq11 2009-04-10
  • 打赏
  • 举报
回复
通过msmq 触发器 实现
参考
jiangwk23 2009-04-10
  • 打赏
  • 举报
回复
up

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧