未验证 提交 1ff98f58 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #47900 from sharwell/avoid-exceptions

Avoid cancellation exceptions when possible for expedited waits
...@@ -42,7 +42,15 @@ public AsynchronousOperationListener(string featureName, bool enableDiagnosticTo ...@@ -42,7 +42,15 @@ public AsynchronousOperationListener(string featureName, bool enableDiagnosticTo
public async Task<bool> Delay(TimeSpan delay, CancellationToken cancellationToken) public async Task<bool> Delay(TimeSpan delay, CancellationToken cancellationToken)
{ {
cancellationToken.ThrowIfCancellationRequested();
var expeditedDelayCancellationToken = _expeditedDelayCancellationTokenSource.Token; var expeditedDelayCancellationToken = _expeditedDelayCancellationTokenSource.Token;
if (expeditedDelayCancellationToken.IsCancellationRequested)
{
// The operation is already being expedited
return false;
}
using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, expeditedDelayCancellationToken); using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, expeditedDelayCancellationToken);
try try
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册