[英]MSMQ: MessageQueue.Close() throws exception -1073741536 at .EndReceive()
I'm using MSMQ inside a Windows Service. 我在Windows服务中使用MSMQ 。
When the service is paused, I'd like to close MSMQ and reopen it when the service is resumed. 暂停服务后,我想关闭MSMQ并在恢复服务时重新打开它。
The code looks like this: 代码如下:
OnStart 的OnStart
_mq.ReceiveCompleted += this.ReceiveCompletedHandler;
_mq.BeginReceive();
OnPause 在onPause
// MessageQueue.ClearConnectionCache();
_mq.Close();
OnContinue OnContinue
same as OnStart
与OnStart相同
Now, this works BUT after .Close()
an exception is thrown in the ReceiveCompletedHandler
: 现在,这在
.Close()
之后仍然有效,但是在ReceiveCompletedHandler
引发了异常:
private void ReceiveCompletedHandler(object sender, ReceiveCompletedEventArgs e)
{
Message message = this.mq.EndReceive(e.AsyncResult); // or e.Message
// do stuff
}
Exception details: 异常详细信息:
Type: MessageQueueException
类型:
MessageQueueException
Message: null
讯息:
null
ErrorCode: -2147467259
错误代码:
-2147467259
MessageQueueErrorCode: -1073741536
MessageQueueErrorCode:
-1073741536
How do I prevent this from happening ? 如何防止这种情况发生 ?
David, 大卫,
In your OnPause try do this before call Close() method: 在您的OnPause中,尝试在调用Close()方法之前执行此操作:
_mq.ReceiveCompleted -= this.ReceiveCompletedHandler; _mq.ReceiveCompleted-= this.ReceiveCompletedHandler;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.