提交 e89c14b6 编写于 作者: S Sam Harwell

Force cancellation if switching to UI thread completed after cancellation request

上级 6d88f91c
......@@ -269,6 +269,8 @@ private void UpdateReferenceLocationsTask(Task<IInlineRenameLocationSet> allRena
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationTokenSource.Token);
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
RaiseSessionSpansUpdated(t.Result.Locations.ToImmutableArray());
},
_cancellationTokenSource.Token,
......@@ -513,6 +515,8 @@ private void QueueApplyReplacements()
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _conflictResolutionTaskCancellationSource.Token);
_conflictResolutionTaskCancellationSource.Token.ThrowIfCancellationRequested();
ApplyReplacements(t.Result.replacementInfo, t.Result.mergeResult, _conflictResolutionTaskCancellationSource.Token);
},
_conflictResolutionTaskCancellationSource.Token,
......
......@@ -36,6 +36,7 @@ public async Task GetSymbolsAsync(GoToSymbolContext context)
// This means we have to query for "third party navigation", from
// XAML, etc. That call has to be done on the UI thread.
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, document.Project, thirdPartyNavigationAllowed: true, cancellationToken)
.WhereAsArray(d => d.CanNavigateTo(document.Project.Solution.Workspace));
......
......@@ -522,6 +522,7 @@ private async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(Project p
// Have to see if this fix is still applicable. Jump to the foreground thread
// to make that check.
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
var applicable = fix.Action.IsApplicable(document.Project.Solution.Workspace);
......
......@@ -148,6 +148,7 @@ public virtual void Stop()
async tasks =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _stopCancellationToken);
_stopCancellationToken.ThrowIfCancellationRequested();
if (tasks.All(t => t.Status == TaskStatus.RanToCompletion))
{
......
......@@ -145,6 +145,8 @@ private void StartSelectedItemUpdateTask(int delay, bool updateUIWhenDone)
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
PushSelectedItemsToPresenter(t.Result);
},
cancellationToken,
......
......@@ -77,6 +77,8 @@ public TrackingSession(StateMachine stateMachine, SnapshotSpan snapshotSpan, IAs
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken);
_cancellationToken.ThrowIfCancellationRequested();
stateMachine.UpdateTrackingSessionIfRenamable();
},
_cancellationToken,
......@@ -103,6 +105,7 @@ private void QueueUpdateToStateMachine(StateMachine stateMachine, Task task)
task.SafeContinueWithFromAsync(async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken);
_cancellationToken.ThrowIfCancellationRequested();
if (_isRenamableIdentifierTask.Result != TriggerIdentifierKind.NotRenamable)
{
......
......@@ -87,6 +87,8 @@ public Task InvokeBelowInputPriorityAsync(Action action, CancellationToken cance
async () =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
action();
},
cancellationToken,
......
......@@ -116,6 +116,8 @@ public void Cancel()
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationTokenSource.Token);
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
if (t.Result != null)
{
commandHandler.EventHookupSessionManager.EventHookupFoundInSession(this);
......
......@@ -145,6 +145,8 @@ private async Task<bool> IsCpsProjectAsync(Project project, CancellationToken ca
var vsWorkspace = project.Solution.Workspace as VisualStudioWorkspaceImpl;
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
var cps = vsWorkspace?.IsCPSProject(project) == true;
// The remainder of this method does not need to execute on the UI thread, but it's pointless to force a
......
......@@ -371,6 +371,8 @@ private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
async _ =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
ProcessBatchedChangesOnForeground(cancellationToken);
},
cancellationToken,
......@@ -414,6 +416,8 @@ private void ProcessBatchedChangesOnForeground(CancellationToken cancellationTok
async () =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
ProcessBatchedChangesOnForeground(cancellationToken);
},
cancellationToken,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册