简体   繁体   English

为什么我的MessageQueue无法正常关闭?

[英]Why won't my MessageQueue close properly?

How can I stop a synchronous or asynchronous Receive from a MessageQueue in C#? 如何停止C#中来自MessageQueue的同步或异步接收?

I find that if I haven't received any messages from the queue since I opened it, I can simply Close / Dispose the queue, and the Receive or EndReceive method will except, which is fine. 我发现,如果自打开队列以来没有收到任何消息,我可以简单地关闭/处置队列,然后使用Receive或EndReceive方法可以,但是可以。 However, if I've already successfully received a message from the queue, I can close and dispose the queue, but the pending or asynchronous receive will carry on regardless! 但是,如果已经从队列中成功接收到消息,则可以关闭并处理队列,但是无论如何,未决或异步接收都会继续!

I've read elsewhere and found some suggestion that I should get EnableConnectionCache to false to ensure the message queue is closed when I ask, but it still seems to be ignore me regardless. 我在其他地方阅读过,发现了一些建议,我应该将EnableConnectionCache设置为false以确保在我询问时关闭消息队列,但是无论如何它仍然似乎忽略了我。

As binarycoder suggested, I have found that this is just a consequence of non-transactional queues. 正如binarycoder建议的那样,我发现这只是非事务性队列的结果。 At least as far as MSMQ goes. 至少就MSMQ而言。 A peek > receive pattern will solve the problem, but only if there is one reader. 窥视>接收模式将解决问题,但前提是只有一个读者。 Otherwise, if you have the same issue you'll have to use transactional queues. 否则,如果您遇到相同的问题,则必须使用事务性队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM