Link to home
Start Free TrialLog in
Avatar of BJohnston
BJohnston

asked on

MSMQ Async Bug?

I have an application that is using MSMQ.

I have written an event handler to handle async message receiving.

it looks something like this :

Private Sub handler(ByVal objt00 As Object, ByVal objt01 As ReceiveCompletedEventArgs)
...
...
' SHOULD BE TRUE IF THERE IS A MESSAGE, FALSE IF TIMEOUT EXPIRED
If objt01.AsyncResult.IsCompleted Then
 ' process message
Else
 ' look to see if shutdown waithandle has occured
 ' if not, resume listening with BeginReceive(TimeSpan)
End If
...
...
End Sub

I initially call BeginReceive(TimeSpan) in a different function

The problem I have is that even if the timeout expires the AsyncResult.IsCompleted flag is true - and there are no messages to process
Has anyone else had this problem or know what I'm doing wrong?

Thanks.
Avatar of BJohnston
BJohnston

ASKER

As an addendum to my previous post, this is the MSDN documentation from which I am drawing my conclusions as to how the event handler should function. . .

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemmessagingmessagequeueclassbeginreceivetopic2.asp


note especially the portion that reads...

This overload specifies a time-out. If the interval specified by the timeout parameter expires, this component raises the ReceiveCompleted event, but the IsCompleted property of the operation's associated IAsyncResult is false. Because no message exists, a subsequent call to EndReceive will throw an exception.



I have temporarily patched this by simply catching the exception generated by the errant call to EndReceive and started BeginReceive again. . . sigh
intresting, the documentation agrees ... what if anything is the state of the result object at this point.
Having talked with a Microsoft technical representative i have been informed that there is a documentation error and that regardless of what triggers the callback (either a Message arrival or a timeout) the AsyncResult.IsCompleted flag will be true.
documentation error ... hmm ... sounds more like a functionality flaw to me :)
Please refund points as there was no answer to be had.  Thank you.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial