System.Threading.HostExecutionContextManager.Revert C# (CSharp) Method

Revert() public method

public Revert ( object previousState ) : void
previousState object
return void
        public virtual void Revert(object previousState)
        {
            var switcher = previousState as HostExecutionContextSwitcher;
            if (switcher == null)
            {
                throw new InvalidOperationException(
                    SR.HostExecutionContextManager_InvalidOperation_CannotOverrideSetWithoutRevert);
            }

            if (t_currentContext != switcher._currentContext || switcher._asyncLocal == null || !switcher._asyncLocal.Value)
            {
                throw new InvalidOperationException(
                    SR.HostExecutionContextManager_InvalidOperation_CannotUseSwitcherOtherThread);
            }
            switcher._asyncLocal = null; // cannot be reused

            // Revert always reverts to a null host execution context when not hosted
            t_currentContext = null;
        }

Usage Example

示例#1
0
 public static void Undo(object switcherObject)
 {
     if (switcherObject != null)
     {
         HostExecutionContextManager currentHostExecutionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();
         if (currentHostExecutionContextManager != null)
         {
             currentHostExecutionContextManager.Revert(switcherObject);
         }
     }
 }
All Usage Examples Of System.Threading.HostExecutionContextManager::Revert