该类BackgroundService
包含以下代码:
public virtual Task StartAsync(CancellationToken cancellationToken)
{
// Store the task we're executing
_executingTask = ExecuteAsync(_stoppingCts.Token);
// If the task is completed then return it, this will bubble cancellation and failure to the caller
if (_executingTask.IsCompleted)
{
return _executingTask;
}
// Otherwise it's running
return Task.CompletedTask;
}
我读过https://www.markopapic.com/csharp-under-the-hood-async-await/这让我假设所有代码ExecuteAsync
到它的第一个(如果有的话)await ...
,在if (_executingTask.IsCompleted)
到达之前执行。因此,如果 的那部分发生任何异常ExecuteAsync
,或者如果ExecuteAsync
返回Task.CompletedTask
,那将导致执行return _executingTask;
。
我对此的理解正确吗?
慕田峪7331174
相关分类