T
Tony Hamill
Hi,
I am trying to create a C# application ( eventually a windows Service )
which will pick up the event when a message enters MSMQ. When this happens I
want to log isome message details.This seems fairly straightforward.
I had assumed using delegates was the way to go and found the following on
msdn (
http://msdn.microsoft.com/library/d...ingreceivecompletedeventhandlerclasstopic.asp )
The problem is that when I run the code provided, my message does indeed get
removed from the queue, but I do not get anything logged to my console. Can
someone tell me why. I had assumed that the event would be raised, this
would call the MyReceiveCompleted method and write something to the console.
This doesn't seem to be the case, though as I said the message I had sent to
the queue previously has disappeared.
code:
using System;
using System.Messaging;
namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous receive operation
// processing.
//**************************************************
public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Add an event handler for the ReceiveCompleted event.
myQueue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MyReceiveCompleted);
// Begin the asynchronous receive operation.
myQueue.BeginReceive();
// Do other work on the current thread.
return;
}
//**************************************************
// Provides an event handler for the ReceiveCompleted
// event.
//**************************************************
private static void MyReceiveCompleted(Object source,
ReceiveCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;
// End the asynchronous Receive operation.
Message m = mq.EndReceive(asyncResult.AsyncResult);
// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);
// Restart the asynchronous Receive operation.
mq.BeginReceive();
return;
}
}
}
any help greatly appreciated.
I am trying to create a C# application ( eventually a windows Service )
which will pick up the event when a message enters MSMQ. When this happens I
want to log isome message details.This seems fairly straightforward.
I had assumed using delegates was the way to go and found the following on
msdn (
http://msdn.microsoft.com/library/d...ingreceivecompletedeventhandlerclasstopic.asp )
The problem is that when I run the code provided, my message does indeed get
removed from the queue, but I do not get anything logged to my console. Can
someone tell me why. I had assumed that the event would be raised, this
would call the MyReceiveCompleted method and write something to the console.
This doesn't seem to be the case, though as I said the message I had sent to
the queue previously has disappeared.
code:
using System;
using System.Messaging;
namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous receive operation
// processing.
//**************************************************
public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Add an event handler for the ReceiveCompleted event.
myQueue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MyReceiveCompleted);
// Begin the asynchronous receive operation.
myQueue.BeginReceive();
// Do other work on the current thread.
return;
}
//**************************************************
// Provides an event handler for the ReceiveCompleted
// event.
//**************************************************
private static void MyReceiveCompleted(Object source,
ReceiveCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;
// End the asynchronous Receive operation.
Message m = mq.EndReceive(asyncResult.AsyncResult);
// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);
// Restart the asynchronous Receive operation.
mq.BeginReceive();
return;
}
}
}
any help greatly appreciated.