fellowcheng

无可奈何花落去

博客园 首页 新随笔 联系 订阅 管理
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 on 2005-05-10 13:54  乌鸦  阅读(735)  评论(0编辑  收藏  举报