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.IsCompl eted 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.
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.IsCompl
' 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.
intresting, the documentation agrees ... what if anything is the state of the result object at this point.
ASKER
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 :)
ASKER
Please refund points as there was no answer to be had. Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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