Mat*_*int 6 c# azure async-await azureservicebus cancellation-token
在Azure Service Bus队列客户端中,我使用该ReceiveBatchAsync方法等待指定的时间异步接收一批消息.
var messages = await queueClient.ReceiveBatchAsync(10, TimeSpan.FromSeconds(30));
Run Code Online (Sandbox Code Playgroud)
我想彻底关闭我的应用程序,所以我正在实现CancellationToken所有长期运行的异步进程,但似乎没有可以ReceiveBatchAsync取消的重载.
换句话说,我想这样做,但我不能:
var messages = await queueClient.ReceiveBatchAsync(10, TimeSpan.FromSeconds(30),
cancellationToken);
Run Code Online (Sandbox Code Playgroud)
将这样CancellationToken的任务应用于不直接提供的任务的最佳方法是什么?我不想在关机期间等待整整30秒.
你可能可以QueueClient.Abort这样使用:
using (cancellationToken.Register(() => queueClient.Abort())
{
var messages = await queueClient.ReceiveBatchAsync(
10, TimeSpan.FromSeconds(30));
return messages; // or process it
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1879 次 |
| 最近记录: |