F
felecha
I have a VB.Net application that runs as a Windows Service and
monitors a MessageQueue on another machine. At times that machine
will have to be rebooted, so I've been working on how to get my
Service to re-establish the connection after the remote machine is
back.
I found that as soon as the remote machine goes down, the
BeginReceive() method and the ReceiveCompleted() event handler start
throwing an exception, for QueueNotAvailable, which is very
reasonable. I figured I would catch the exception, tell the
CurrentThread to sleep for, say, 5 seconds, then instantiate the
MessageQueue object again, set its Formatter, add the handler, and
call BeginReceive again. I thought it should continue throwing the
same exception and reinstantiating itself until the remote
MessageQueue is on again.
But now I find that after the new MessageQueue is up (which I can see
in my debugging log) the EndReceive() method called inside the
ReceiveCompleted() throws another exception - "An invalid handle
was passed to the function." I thought maybe the new MessageQueue
instance was null or somehow not right, but I've put debug lines in
to check the MessageQueue properties and the properties of the
AsyncResult passed to EndReceive(), and they are all non-null, so I
figure that's not the problem.
Any clues?
monitors a MessageQueue on another machine. At times that machine
will have to be rebooted, so I've been working on how to get my
Service to re-establish the connection after the remote machine is
back.
I found that as soon as the remote machine goes down, the
BeginReceive() method and the ReceiveCompleted() event handler start
throwing an exception, for QueueNotAvailable, which is very
reasonable. I figured I would catch the exception, tell the
CurrentThread to sleep for, say, 5 seconds, then instantiate the
MessageQueue object again, set its Formatter, add the handler, and
call BeginReceive again. I thought it should continue throwing the
same exception and reinstantiating itself until the remote
MessageQueue is on again.
But now I find that after the new MessageQueue is up (which I can see
in my debugging log) the EndReceive() method called inside the
ReceiveCompleted() throws another exception - "An invalid handle
was passed to the function." I thought maybe the new MessageQueue
instance was null or somehow not right, but I've put debug lines in
to check the MessageQueue properties and the properties of the
AsyncResult passed to EndReceive(), and they are all non-null, so I
figure that's not the problem.
Any clues?