2014-04-25 66 views
1

我调用BeginReceive()在这样一个SubscriptionClient:)天青ServiceBus SubscriptionClient.EndReceive()返回null

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

而在DownloadResults(回调我叫client.EndReceive()客户端是一个静态成员类]的

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()中指定的时间限制已超出?还是因为有错误?

回答

1

看来,如果超过了时间限制,回调被调用。当我们尝试通过调用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

0

用于接收该ServiceBus不会抛出异常状态的合同。当Receive/BeginReceive/ReceiveAsync超时时,该调用将执行它需要做的任何操作以返回值(例如执行回调),并且在超时情况下将返回null。