我在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
。通过在MSDN页面上查看SubscriptionClient.EndReceive()到底是什么时候EndReceive()返回,对我来说还不是很清楚null
。是否因为超过了我在BeginReceive()中指定的时限?还是因为有错误?
似乎如果超过了时间限制,则会调用该回调。当我们尝试通过调用检索消息时SubscriptionClient.EndReceive()
,null
将返回。
默认超时值为一分钟,并且无法设置无限超时。如果您希望无限超时,SubscriptionClient.BeginReceive()
则如果消息为,则可以再次呼叫null
。
例如:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句