如何停止从设置为事件驱动消息泵的订阅客户端接收消息?我目前有一些代码可以工作,但是当我连续运行两个测试时,它们会第二次中断。我相当确定消息仍在从我创建的第一个实例中脱离订阅。
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);
最佳答案
您可以调用SubscriptionClient.Close()
停止进一步的消息处理。
在代码的注释中也指出:
关于c# - 停止接收来自 SubscriptionClient 的消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17025338/