Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do dequeue messages from a MSMQ Queue in a service hosted in a WPF application?

Posted on 2013-07-01
1
1,055 Views
Last Modified: 2013-07-09
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:
External App --> WebService           --> WPF Application
Sends msg           hosted on thread       receives msg
--------------       in WPF application      & takes appropriate action

Open in new window


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

Open in new window


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.Dispatcher.BeginInvoke()

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

         }
  }

Open in new window


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
0
Comment
Question by:jxbma
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39292417
in your while scope u create new Action every loop, which eventually causes the machine to hung.
for .net 4 and later use the example shown here:
http://angelolaris.blogspot.co.il/2012/02/comparing-old-and-new-asynchronous-msmq.html
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with preventing selection from a combobox 11 34
how to check group permission on a file located on a remote server ? 3 24
linq, c# 8 23
Visual Studio npm 1 12
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question