public void Replace() { var syncContext = Current; if (syncContext == null) throw new InvalidOperationException( "Ensure a synchronization context exists before calling this method."); var customSynchronizationContext = syncContext as AsyncExceptionSwallowingContext; if (customSynchronizationContext == null) { customSynchronizationContext = new AsyncExceptionSwallowingContext(syncContext); SetSynchronizationContext(customSynchronizationContext); } else { SetSynchronizationContext(_syncContext); } }
public void Replace() { var syncContext = Current; if (syncContext == null) { throw new InvalidOperationException( "Ensure a synchronization context exists before calling this method."); } var customSynchronizationContext = syncContext as AsyncExceptionSwallowingContext; if (customSynchronizationContext == null) { customSynchronizationContext = new AsyncExceptionSwallowingContext(syncContext); SetSynchronizationContext(customSynchronizationContext); } else { SetSynchronizationContext(_syncContext); } }