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));
}
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));
}