Skip to content

Commit a991beb

Browse files
Fix tasks never completing if cancelled quickly
We were exiting SynchronousTask.ExecuteSynchronously early if the cancellation was already requested. This was not setting our tcs state correctly, causing the caller to just fall off without warning.
1 parent 5df33bb commit a991beb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousTask.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected SynchronousTask(
3535
CancellationToken cancellationToken)
3636
{
3737
Logger = logger;
38-
_taskCompletionSource = new TaskCompletionSource<TResult>();
38+
_taskCompletionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
3939
_taskRequesterCancellationToken = cancellationToken;
4040
_executionCanceled = false;
4141
}
@@ -76,6 +76,7 @@ public void ExecuteSynchronously(CancellationToken executorCancellationToken)
7676
{
7777
if (IsCanceled)
7878
{
79+
SetCanceled();
7980
return;
8081
}
8182

0 commit comments

Comments
 (0)