首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >停止接收来自SubscriptionClient的消息

停止接收来自SubscriptionClient的消息
EN

Stack Overflow用户
提问于 2013-06-10 21:42:03
回答 3查看 2.7K关注 0票数 7

如何停止从设置为事件驱动消息泵的订阅客户端接收消息?我目前有一些代码可以正常工作,但是当我连续运行两个测试时,它们会出现第二次中断。我非常确定,从我创建的第一个实例开始,消息仍然会从订阅中删除。

http://msdn.microsoft.com/en-us/library/dn130336.aspx

代码语言:javascript
复制
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);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-06-11 06:35:00

您可以调用SubscriptionClient.Close()来停止进一步的消息处理。

在代码的注释中也指出了:

在客户机上调用Close()将停止泵。

票数 3
EN

Stack Overflow用户

发布于 2016-07-28 22:26:30

你需要做两件事。

首先,调用subscriptionClient.Close(),它将最终(但不是立即)停止消息泵。

第二,在收到消息回调时,检查客户端是否关闭,如下所示:

代码语言:javascript
复制
if (subscriptionClient.IsClosed)
    return;
票数 6
EN

Stack Overflow用户

发布于 2015-08-06 22:55:42

我看了看,看到了完全相同的行为。即使您关闭订阅客户端,消息泵也不会停止尝试处理消息。需要一个方法来阻止加油站的人。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17025338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档