Skip to content

Commit

Permalink
Fixes microsoft#544. Replaced the condition checking whether this.job…
Browse files Browse the repository at this point in the history
… exists with an assert instead. SingleExecuteProtector can only ever be constructed with a non-null job (validates with Requires.NotNull) and the job is only set to null after TryExecute succeeds. Therefore the job will exist if TryExecute has an invokeDelegate (i.e. has not yet executed). Removed the #pragma that disabled the CS8602 warning.
  • Loading branch information
bluetarpmedia committed Jun 28, 2021
1 parent a0ab9d8 commit 42fbc0f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Expand Up @@ -1227,9 +1227,8 @@ internal bool TryExecute()
if (invokeDelegate is object)
{
this.OnExecuting();
#pragma warning disable CS8602 // Dereference of a possibly null reference.
SynchronizationContext? syncContext = this.job is object ? this.job.ApplicableJobSyncContext : this.job.Factory.ApplicableJobSyncContext;
#pragma warning restore CS8602 // Dereference of a possibly null reference.
RoslynDebug.Assert(this.job is object);
SynchronizationContext? syncContext = this.job.ApplicableJobSyncContext;
using (syncContext.Apply(checkForChangesOnRevert: false))
{
if (invokeDelegate is Action action)
Expand Down

0 comments on commit 42fbc0f

Please sign in to comment.