Skip to content

Commit

Permalink
Support restoring a null initial synchronisation context
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed May 2, 2024
1 parent 2a0c631 commit cfcab31
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public static IDisposable Suppress()

private sealed class SuppressionReleaser(SynchronizationContext old) : IDisposable
{
private SynchronizationContext? old = old;
private int _isDisposed;

public void Dispose()
{
if (Interlocked.Exchange(ref old, null) is { } restoreMe)
if (Interlocked.Exchange(ref _isDisposed, 1) is 0)
{
SynchronizationContext.SetSynchronizationContext(restoreMe);
SynchronizationContext.SetSynchronizationContext(old);
}
}
}
Expand Down

0 comments on commit cfcab31

Please sign in to comment.