jxbma
asked on
How do dequeue messages from a MSMQ Queue in a service hosted in a WPF application?
Hi:
I have a WPF application that's hosting a WebService in a thread.
Clients connect to the service and send commands over the wire to the service.
The service in turn, places messages on queue to be consumed by the WPF application.
The WPF application connects to the queue and dequeues the message (consumes) and takes appropriate action.
So the flow of control is:
This all works fine and well.
Now, I need to push notifications from my WPF app back to the WebService. From there, the WebService can call back (via call back to the client). I want to keep that line of communication separate from the Service->WPFHostApp MsgQueue, so I created a new MsgQueue for pushing pushing messages from the WPFHostApp->Service.
So the flow of control back to the host isis:
The question I have is, what is the best method for pulling messages of the (WPFHostApp->Service) MsgQueue? Remember that this will be done in Service. I tried using
launching a new thread and doing Application.Current.Dispat cher.Begin Invoke()
However, this did not work as expected. It basically hung the machine (ate up the CPU).
I would like to keep this basic architecture. I just need assistance in pulling messages of a queue within a thread (hosted service).
Thanks,
JohnB
I have a WPF application that's hosting a WebService in a thread.
Clients connect to the service and send commands over the wire to the service.
The service in turn, places messages on queue to be consumed by the WPF application.
The WPF application connects to the queue and dequeues the message (consumes) and takes appropriate action.
So the flow of control is:
External App --> WebService --> WPF Application
Sends msg hosted on thread receives msg
-------------- in WPF application & takes appropriate action
This all works fine and well.
Now, I need to push notifications from my WPF app back to the WebService. From there, the WebService can call back (via call back to the client). I want to keep that line of communication separate from the Service->WPFHostApp MsgQueue, so I created a new MsgQueue for pushing pushing messages from the WPFHostApp->Service.
So the flow of control back to the host isis:
WPF Application --> WebService --> In turn WebService
Sends message receives msg and notifies client application.
on msg queue takes appropriate action
The question I have is, what is the best method for pulling messages of the (WPFHostApp->Service) MsgQueue? Remember that this will be done in Service. I tried using
launching a new thread and doing Application.Current.Dispat
void RPIReturnMessageProcessorThread_DoWork(object sender, DoWorkEventArgs e)
{
// First thing is to remove all the previous messages in the queue
this.m_RPIReturnMessageQueue.Purge();
while (true)
{
Application.Current.Dispatcher.BeginInvoke(
new Action(
() =>
{
var message = m_RPIReturnMessageQueue.Receive();
if (message != null)
{
Console.WriteLine("GetStatus Message Received");
Console.WriteLine(message.Body.ToString());
ClientCallBackNotification.Notification("Reporting Facility",
"GetStatus return parameter values.",
message.Body);
}
}
), null);
}
}
However, this did not work as expected. It basically hung the machine (ate up the CPU).
I would like to keep this basic architecture. I just need assistance in pulling messages of a queue within a thread (hosted service).
Thanks,
JohnB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.