消息队列异步处理

消息队列异步处理

作者:飞鸟 | 出处:博客园 | 2011/9/19 5:07:02 | 阅读22
private System.Messaging.MessageQueue mqAsy;
private void AsyReceive()
{
if(MessageQueue.Exists(@".\myQueue"))
//creates an instance MessageQueue, which points to the already existing MyQueue
mqAsy = new System.Messaging.MessageQueue(@".\myQueue");
else
//creates a new private queue called MyQueue
mqAsy = MessageQueue.Create(@".\myQueue");
mqAsy.ReceiveCompleted+=new ReceiveCompletedEventHandler(mqAsy_ReceiveCompleted);
mqAsy.BeginReceive(new TimeSpan(0,0,1));
}

private void mqAsy_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
System.Messaging.Message m= mqAsy.EndReceive(e.AsyncResult);
m.Formatter = new XmlMessageFormatter(new String[]{"System.String,mscorlib"});
if(m.Body.ToString()!=null)
{
// input your code here
}
mqAsy.BeginReceive(new TimeSpan(0,0,1));
}
posted @ 2012-09-24 17:01  yuloe2012  阅读(1740)  评论(0编辑  收藏  举报