如何停止从设置为事件驱动消息泵的订阅客户端接收消息?我目前有一些代码可以正常工作,但是当我连续运行两个测试时,它们会出现第二次中断。我非常确定,从我创建的第一个实例开始,消息仍然会从订阅中删除。
http://msdn.microsoft.com/en-us/library/dn130336.aspx
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = true; // Indicates if the message-pump should call complete on messages after the callback has completed processing.
options.MaxConcurrentCalls = 1; // Indicates the maximum number of concurrent calls to the callback the pump should initiate
options.ExceptionReceived += LogErrors; // Enables you to be notified of any errors encountered by the message pump
// Start receiveing messages
Client.OnMessage((receivedMessage) => // Initiates the message pump and callback is invoked for each message that is received. Calling Close() on the client will stop the pump.
{
// Process the message
Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());
}, options);发布于 2013-06-11 06:35:00
您可以调用SubscriptionClient.Close()来停止进一步的消息处理。
在代码的注释中也指出了:
在客户机上调用Close()将停止泵。
发布于 2016-07-28 22:26:30
你需要做两件事。
首先,调用subscriptionClient.Close(),它将最终(但不是立即)停止消息泵。
第二,在收到消息回调时,检查客户端是否关闭,如下所示:
if (subscriptionClient.IsClosed)
return;发布于 2015-08-06 22:55:42
我看了看,看到了完全相同的行为。即使您关闭订阅客户端,消息泵也不会停止尝试处理消息。需要一个方法来阻止加油站的人。
https://stackoverflow.com/questions/17025338
复制相似问题