gpt4 book ai didi

c# - Azure ServiceBus SubscriptionClient.EndReceive() 返回 null

转载 作者:行者123 更新时间:2023-12-03 03:17:04 28 4
gpt4 key购买 nike

我在 SubscriptionClient 上调用 BeginReceive(),如下所示:

client.BeginReceive(new TimeSpan(6, 0, 0), new AsyncCallback(DownloadResults), null);

在 DownloadResults() 回调中,我调用 client.EndReceive() [client 是该类的静态成员]

static public void DownloadResults(IAsyncResult ar)
{
// Get the message from the service bus.
msg = client.EndReceive(ar);
if (msg == null)
{
Console.WriteLine("Error!");
return;
}
}

有时 client.EndReceive() 返回 null。通过查看 SubscriptionClient.EndReceive() 的 MSDN 页面,我不太清楚 EndReceive() 何时返回 null。是因为超出了我在 BeginReceive() 中指定的时间限制吗?还是因为有错误?

最佳答案

看来,如果超过时间限制,就会调用回调。当我们尝试通过调用 SubscriptionClient.EndReceive() 检索消息时,将返回 null

默认超时值为一分钟,并且无法设置无限超时。如果您想要无限超时,则可以在消息为 null 时再次调用 SubscriptionClient.BeginReceive()

例如:

static public void DownloadResults(IAsyncResult ar)
{
// Get the message from the service bus.
msg = client.EndReceive(ar);
if (msg == null)
{
// Start waiting for the message again.
client.BeginReceive(new TimeSpan(6, 0, 0), new AsyncCallback(DownloadResults), null);
return;
}
}

来源:http://social.msdn.microsoft.com/Forums/windowsazure/en-US/b14587ce-3fc7-4b56-8a35-4f2c6babce26/servicebus-subscriptionclientendreceive-returns-null

关于c# - Azure ServiceBus SubscriptionClient.EndReceive() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23288797/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com