提交 323ae90c 编写于 作者: J Jason Malinowski

Disable rather than try to work around VSTHRD103

VSTHRD103 reminds people not to use .Result in tasks, which is great
advice but we get a few false positives; in particular our
SafeContinueWith extension isn't understood by the analyzer that the
tasks involved are always completed, so you can just .Result them.
Rather than working around this, let's just disable the analyzer in
those cases.
上级 bd80cfa2
......@@ -492,10 +492,11 @@ private void QueueApplyReplacements()
return;
}
#pragma warning disable VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
var asyncToken = _asyncListener.BeginAsyncOperation(nameof(QueueApplyReplacements));
_conflictResolutionTask
.SafeContinueWith(
async t => await ComputeMergeResultAsync(await t.ConfigureAwait(false), _conflictResolutionTaskCancellationSource.Token).ConfigureAwait(false),
t => ComputeMergeResultAsync(t.Result, _conflictResolutionTaskCancellationSource.Token),
_conflictResolutionTaskCancellationSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Default)
......@@ -506,6 +507,7 @@ private void QueueApplyReplacements()
TaskContinuationOptions.OnlyOnRanToCompletion,
ForegroundTaskScheduler)
.CompletesAsyncOperation(asyncToken);
#pragma warning restore VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
}
private async Task<(IInlineRenameReplacementInfo replacementInfo, LinkedFileMergeSessionResult mergeResult)> ComputeMergeResultAsync(IInlineRenameReplacementInfo replacementInfo, CancellationToken cancellationToken)
......
......@@ -129,10 +129,12 @@ public virtual void Stop()
// background task complete when its result has finally been displayed on the UI.
var asyncToken = _controller.BeginAsyncOperation();
#pragma warning disable VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
// Create the task that will actually run the transformation step.
var nextTask = _lastTask.SafeContinueWithFromAsync(
async t => await transformModelAsync(await t.ConfigureAwait(false), _stopCancellationToken).ConfigureAwait(false),
t => transformModelAsync(t.Result, _stopCancellationToken),
_stopCancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, _taskScheduler);
#pragma warning restore VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
// The next task is now the last task in the chain.
_lastTask = nextTask;
......
......@@ -112,8 +112,9 @@ internal void CheckNewIdentifier(StateMachine stateMachine, ITextSnapshot snapsh
{
AssertIsForeground();
#pragma warning disable VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
_newIdentifierBindsTask = _isRenamableIdentifierTask.SafeContinueWithFromAsync(
async t => await t.ConfigureAwait(false) != TriggerIdentifierKind.NotRenamable &&
async t => t.Result != TriggerIdentifierKind.NotRenamable &&
TriggerIdentifierKind.RenamableReference ==
await DetermineIfRenamableIdentifierAsync(
TrackingSpan.GetSpan(snapshot),
......@@ -121,6 +122,7 @@ internal void CheckNewIdentifier(StateMachine stateMachine, ITextSnapshot snapsh
_cancellationToken,
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Default);
#pragma warning restore VSTHRD103 // Call async methods when in an async method: .Result is non-blocking inside a SafeContinueWith
QueueUpdateToStateMachine(stateMachine, _newIdentifierBindsTask);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册