/// <summary> /// Initializes a new instance of the <see cref="RevertRelevance"/> struct. /// </summary> /// <param name="pump">The instance that created this value.</param> internal RevertRelevance(JoinableTaskContext pump) { Requires.NotNull(pump, nameof(pump)); this.pump = pump; this.oldJoinable = pump.AmbientTask; pump.AmbientTask = null; var jobSyncContext = SynchronizationContext.Current as JoinableTaskSynchronizationContext; if (jobSyncContext != null) { SynchronizationContext appliedSyncContext = null; if (jobSyncContext.MainThreadAffinitized) { appliedSyncContext = pump.UnderlyingSynchronizationContext; } this.temporarySyncContext = appliedSyncContext.Apply(); // Apply() extension method allows null receiver } else { this.temporarySyncContext = default(SpecializedSyncContext); } }