[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Timeout receiving asyncronous message using msmq

Posted on 2006-06-07
Medium Priority
Last Modified: 2012-06-21

I'm trying to learn more about messaging and services using an example by Peter Bromberg from Egghead Cafe (http://www.eggheadcafe.com/articles/20041204.asp - code can be downloaded from http://www.eggheadcafe.com/articles/20041204.zip). The example runs on a single machine but I've been trying to get it to run with the client and server on seperate machines for about 3 days without luck. I added event log messages at different points and it seems to fall over at the async receive on the server (Invoker.cs in the MSMQInvokerService project):

                                //breaks at this point
                                Message msg=mq.EndReceive(ar);
                                //and goes to the catch
                        ICommand cReceived = (ICommand)msg.Body;
                        ServiceBroker.Logger.WriteToLog("ICommand Object Casted.",
                        ServiceBroker.Logger.WriteToLog("Executed Command at "+DateTime.Now.ToLongTimeString(),

If the service is invoked on the server this means that the message has gotten there, right? What am I doing wrong?

Question by:matt_d_p
  • 3
  • 2
LVL 25

Expert Comment

ID: 16855122
One thing you may try is to post the exception to the event log to see if it actually was a timeout:

               catch(Exception exception)
                    ServiceBroker.Logger.WriteToLog("An Exception Occured:\n" + exception.ToString(),

Author Comment

ID: 16855732
Thanks for the suggestion. Seems it is a timeout out but why? Why the difference between local and remotes? I'm on a home network with 2 pc's linked by a crossover cable. Shouldn't be any load at all.

This is the error in the remote log:

Event Type:      Information
Event Source:      ServiceBroker
Event Category:      None
Event ID:      0
Date:            2006/06/07
Time:            09:45:44 PM
User:            N/A
Computer:      BIGBLACK
An Exception Occured:
System.Messaging.MessageQueueException: Timeout for the requested operation has expired.
   at System.Messaging.MessageQueue.AsynchronousRequest.End()
   at System.Messaging.MessageQueue.EndAsyncOperation(IAsyncResult asyncResult)
   at System.Messaging.MessageQueue.EndReceive(IAsyncResult asyncResult)
   at MSMQInvokerService.Invoker.OnMessageArrival(IAsyncResult ar)

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

While playing I've also introduced a bug in the client now:

FormatName:DIRECT=OS:bigblack\private$\commandtest              //writeline of destinationQueue value
System.Messaging.MessageQueueException: The specified format name does not suppo
rt the requested operation. For example, a direct queue format name cannot be de
   at System.Messaging.MessageQueue.SaveQueueProperties()
   at System.Messaging.MessageQueue.set_UseJournalQueue(Boolean value)
   at ClientSample.QueuedClient.QueueInvokerCommand(ICommand c, String destinati
onQueue) in C:\projects\PosMinder\ClientSample\QueuedClient.cs:line 65

Could this contribute? It complains about the name format yet still seems to get to the server as I see the errors there. Very confusing?
LVL 25

Accepted Solution

dstanley9 earned 1500 total points
ID: 16855812
An exception being thrown doesn't necessarily mean that a message was received:

from http://msdn2.microsoft.com/en-us/system.messaging.messagequeue.endreceive.aspx:
BeginReceive can specify a time-out, which causes the ReceiveCompleted event to be raised if the time-out occurs before a message appears in the queue. When a time-out occurs without a message arriving in the queue, a subsequent call to EndReceive throws an exception.

So perhaps the message is not sent after all.

Author Comment

ID: 16856025
If I understand this correctly, there isn't a problem at the server, the server just writes this message each time it "times out" while checking for a message? That explains why I couldn't find anything wrong :). Let me go and find my real problem. Thanks for the help.
LVL 25

Expert Comment

ID: 16856164
Yes, the ReceivedCompleted event will fire in the event of a timeout, but calling EndReceive if there is no message will cause the exception.  

You can check the IsCompleted property of the AsyncResult object to see if a message was actually received.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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