Inheritance: ISerializable
 internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
 {
     _ioCompletionCallback = ioCompletionCallback;
     // clone the exection context
     _executionContext = ExecutionContext.Capture(ref stackMark);
     ExecutionContext.ClearSyncContext(_executionContext);
 }
Example #2
0
 internal static ExecutionContext Capture(ref StackCrawlMark stackMark)
 {
     if (IsFlowSuppressed())
     {
         return null;
     }
     ExecutionContext executionContextNoCreate = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate();
     ExecutionContext context2 = new ExecutionContext {
         isNewCapture = true,
         SecurityContext = System.Security.SecurityContext.Capture(executionContextNoCreate, ref stackMark)
     };
     if (context2.SecurityContext != null)
     {
         context2.SecurityContext.ExecutionContext = context2;
     }
     context2._hostExecutionContext = HostExecutionContextManager.CaptureHostExecutionContext();
     if (executionContextNoCreate != null)
     {
         context2._syncContext = (executionContextNoCreate._syncContext == null) ? null : executionContextNoCreate._syncContext.CreateCopy();
         if (executionContextNoCreate._logicalCallContext != null)
         {
             System.Runtime.Remoting.Messaging.LogicalCallContext logicalCallContext = executionContextNoCreate.LogicalCallContext;
             context2.LogicalCallContext = (System.Runtime.Remoting.Messaging.LogicalCallContext) logicalCallContext.Clone();
         }
     }
     return context2;
 }
 static ResultDelegate WrapResultDelegate(ExecutionContext context, ResultDelegate result)
 {
     return (status, headers, body) => result(
         status,
         headers,
         WrapBodyDelegate(context, body));
 }
Example #4
0
        //
        // This version of an Ssl Stream is for internal HttpWebrequest use.
        // This Ssl client owns the underlined socket
        // The TlsStream will own secured read/write and disposal of the passed "networkStream" stream.
        //
        public TlsStream(string destinationHost, NetworkStream networkStream, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext)
               :base(networkStream, true) {

        // WebRequest manages the execution context manually so we have to ensure we get one for SSL client certificate demand
        _ExecutionContext = executionContext;
        if (_ExecutionContext == null)
        {
            _ExecutionContext = ExecutionContext.Capture();
        }

        // 


         GlobalLog.Enter("TlsStream::TlsStream", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "none" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
         if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));

         m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
         m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy);

         m_DestinationHost = destinationHost;
         m_ClientCertificates = clientCertificates;

         RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest);
         m_Worker.SetCertValidationDelegate(certValidationCallback);

         // The Handshake is NOT done at this point
         GlobalLog.Leave("TlsStream::TlsStream (Handshake is not done)");
        }
Example #5
0
 internal static void ClearSyncContext(ExecutionContext ec)
 {
     if (ec != null)
     {
         ec.SynchronizationContext = null;
     }
 }
Example #6
0
		public WorkItem(WorkItemId taskID, WaitCallback wc, IAsyncResult state, ExecutionContext ctx)
		{
			_callback = wc;
			_state = state;
			_ctx = ctx;
			_taskID = taskID;
		}
        internal static SecurityContext Capture(System.Threading.ExecutionContext currThreadEC, ref StackCrawlMark stackMark)
        {
            if (IsFlowSuppressed())
            {
                return(null);
            }
            if (CurrentlyInDefaultFTSecurityContext(currThreadEC))
            {
                return(null);
            }
            SecurityContext context = new SecurityContext {
                isNewCapture = true
            };

            if (!IsWindowsIdentityFlowSuppressed())
            {
                System.Security.Principal.WindowsIdentity currentWI = GetCurrentWI(currThreadEC);
                if (currentWI != null)
                {
                    context._windowsIdentity = new System.Security.Principal.WindowsIdentity(currentWI.TokenHandle);
                }
            }
            else
            {
                context._disableFlow = SecurityContextDisableFlow.WI;
            }
            context.CompressedStack = System.Threading.CompressedStack.GetCompressedStack(ref stackMark);
            return(context);
        }
 static BodyDelegate WrapBodyDelegate(ExecutionContext context, BodyDelegate body)
 {
     return body == null ? (BodyDelegate)null : (write, flush, end, cancellationToken) => ExecutionContext.Run(
         context.CreateCopy(),
         _ => body(write, WrapFlushDelegate(context, flush), end, cancellationToken),
         null);
 }
 public SynchronizationContextSwitcher(SynchronizationContext context)
 {
     _newContext = context;
     _executionContext = Thread.CurrentThread.ExecutionContext;
     _oldContext = SynchronizationContext.Current;
     SynchronizationContext.SetSynchronizationContext(context);
 }
Example #10
0
		internal ExecutionContext (ExecutionContext ec)
		{
			if (ec._sc != null)
				_sc = new SecurityContext (ec._sc);
			_suppressFlow = ec._suppressFlow;
			_capture = true;
		}
		protected CimAsyncCallbacksReceiverBase()
		{
			this._operationLock = new object();
			this._operationPendingActions = new List<Action<CimOperation>>();
			this._suppressFurtherUserCallbacksLock = new object();
			this._threadExecutionContext = ExecutionContext.Capture();
		}
 public void Undo()
 {
     if (this.currEC != null)
     {
         if (this.currEC != Thread.CurrentThread.GetExecutionContextNoCreate())
         {
             Environment.FailFast(Environment.GetResourceString("InvalidOperation_SwitcherCtxMismatch"));
         }
         if (this.currSC != this.currEC.SecurityContext)
         {
             Environment.FailFast(Environment.GetResourceString("InvalidOperation_SwitcherCtxMismatch"));
         }
         this.currEC.SecurityContext = this.prevSC;
         this.currEC = null;
         bool flag = true;
         try
         {
             if (this.wic != null)
             {
                 flag &= this.wic.UndoNoThrow();
             }
         }
         catch
         {
             flag &= this.cssw.UndoNoThrow();
             Environment.FailFast(Environment.GetResourceString("ExecutionContext_UndoFailed"));
         }
         if (!(flag & this.cssw.UndoNoThrow()))
         {
             Environment.FailFast(Environment.GetResourceString("ExecutionContext_UndoFailed"));
         }
     }
 }
Example #13
0
 internal void Setup()
 {
     this.useEC = true;
     this._ec = Thread.CurrentThread.ExecutionContext;
     this._ec.isFlowSuppressed = true;
     this._thread = Thread.CurrentThread;
 }
Example #14
0
	internal AsyncResult (WaitCallback cb, object state, bool capture_context)
	{
		async_state = state;
		async_delegate = cb;
		if (capture_context)
			current = ExecutionContext.Capture ();
	}
 internal CancellationCallbackInfo(Action<object> callback, object stateForCallback, SynchronizationContext targetSyncContext, ExecutionContext targetExecutionContext, System.Threading.CancellationTokenSource cancellationTokenSource)
 {
     this.Callback = callback;
     this.StateForCallback = stateForCallback;
     this.TargetSyncContext = targetSyncContext;
     this.TargetExecutionContext = targetExecutionContext;
     this.CancellationTokenSource = cancellationTokenSource;
 }
Example #16
0
 internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
 {
     _ioCompletionCallback = ioCompletionCallback;
     // clone the exection context
     _executionContext = ExecutionContext.Capture(
         ref stackMark, 
         ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
 }
Example #17
0
			public void Restore (ExecutionContext ec)
			{
				ec._lcc = this._lcc;
				ec._suppressFlow = this._suppressFlow;
				ec._capture = this._capture;
				ec.local_data = this.local_data;
				ec.CopyOnWrite = this.copy_on_write;
			}
Example #18
0
 static Action<ResultParameters, Exception> WrapCallbackDelegate(ExecutionContext context, Action<ResultParameters, Exception> callback)
 {
     return (result, error) =>
     {
         result.Body = WrapBodyDelegate(context, result.Body);
         callback(result, error);
     };
 }
Example #19
0
 internal CallbackClosure(ExecutionContext context, AsyncCallback callback)
 {
     if (callback != null)
     {
         _savedCallback = callback;
         _savedContext = context;
     }
 }
 internal CancellationCallbackInfo(Action<object> callback, object stateForCallback, SynchronizationContext targetSyncContext, ExecutionContext targetExecutionContext, CancellationTokenSource cancellationTokenSource)
 {
     Callback = callback;
     StateForCallback = stateForCallback;
     TargetSyncContext = targetSyncContext;
     TargetExecutionContext = targetExecutionContext;
     CancellationTokenSource = cancellationTokenSource;
 }
Example #21
0
			public Switcher (ExecutionContext ec)
			{
				this.ec = ec;
				this._lcc = ec._lcc;
				this._suppressFlow = ec._suppressFlow;
				this._capture = ec._capture;
				this.local_data = ec.local_data;
				this.copy_on_write = ec.CopyOnWrite;
			}
 internal QueueUserWorkItemCallback(WaitCallback waitCallback, object stateObj, bool compressStack, ref StackCrawlMark stackMark)
 {
     this.callback = waitCallback;
     this.state = stateObj;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this.context = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
		internal ExecutionContext (ExecutionContext ec)
		{
#if !MOONLIGHT
			if (ec._sc != null)
				_sc = new SecurityContext (ec._sc);
#endif
			_suppressFlow = ec._suppressFlow;
			_capture = true;
		}
Example #24
0
        public IObservable<Unit> Execute(ExecutionContext context)
        {
            Ensure.ArgumentNotNull(context, nameof(context));

            return context
                .WaitWhilePaused()
                .SelectMany(_ => this.speechService.Speak(this.speechText))
                .FirstAsync();
        }
 internal static SecurityContext GetCurrentSecurityContextNoCreate()
 {
     System.Threading.ExecutionContext executionContextNoCreate = Thread.CurrentThread.GetExecutionContextNoCreate();
     if (executionContextNoCreate != null)
     {
         return(executionContextNoCreate.SecurityContext);
     }
     return(null);
 }
Example #26
0
		internal ExecutionContext (ExecutionContext ec)
		{
#if !NET_2_1 || MONOTOUCH
			if (ec._sc != null)
				_sc = new SecurityContext (ec._sc);
#endif
			_suppressFlow = ec._suppressFlow;
			_capture = true;
		}
 internal _ThreadPoolWaitCallback(WaitCallback waitCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
 {
     this._waitCallback = waitCallback;
     this._state = state;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
 internal DbAsyncResult(object owner, string endMethodName, AsyncCallback callback, object stateObject, ExecutionContext execContext)
 {
     this._owner = owner;
     this._endMethodName = endMethodName;
     this._callback = callback;
     this._stateObject = stateObject;
     this._manualResetEvent = new ManualResetEvent(false);
     this._execContext = execContext;
 }
 internal _TimerCallback(TimerCallback timerCallback, object state, ref StackCrawlMark stackMark)
 {
     this._timerCallback = timerCallback;
     this._state = state;
     if (!ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
 internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
 {
     this._waitOrTimerCallback = waitOrTimerCallback;
     this._state = state;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark);
         ExecutionContext.ClearSyncContext(this._executionContext);
     }
 }
Example #31
0
        private ExecutionContext(ExecutionContext other)
        {
            m_localValues = new LowLevelDictionaryWithIEnumerable<IAsyncLocal, object>();
            foreach (KeyValuePair<IAsyncLocal, object> kvp in other.m_localValues)
            {
                m_localValues.Add(kvp.Key, kvp.Value);
            }

            m_localChangeNotifications = new LowLevelListWithIList<IAsyncLocal>(other.m_localChangeNotifications);
        }
Example #32
0
 internal _TimerCallback(TimerCallback timerCallback, Object state, ref StackCrawlMark stackMark)
 {
     _timerCallback = timerCallback;
     _state = state;
     if (!ExecutionContext.IsFlowSuppressed())
     {
         _executionContext = ExecutionContext.Capture(ref stackMark);
         ExecutionContext.ClearSyncContext(_executionContext);
     }
 }
        internal static System.Security.Principal.WindowsIdentity GetCurrentWI(System.Threading.ExecutionContext threadEC)
        {
            if (_alwaysFlowImpersonationPolicy)
            {
                return(System.Security.Principal.WindowsIdentity.GetCurrentInternal(TokenAccessLevels.MaximumAllowed, true));
            }
            SecurityContext context = (threadEC == null) ? null : threadEC.SecurityContext;

            if (context != null)
            {
                return(context.WindowsIdentity);
            }
            return(null);
        }
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext prevSecurityContext, ref StackCrawlMark stackMark)
        {
            SecurityContextDisableFlow flow = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;
            SecurityContextSwitcher switcher = new SecurityContextSwitcher {
                currSC = sc
            };

            System.Threading.ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;
            switcher.currEC = executionContext;
            switcher.prevSC = prevSecurityContext;
            executionContext.SecurityContext = sc;
            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    switcher.wic = null;
                    if (!_LegacyImpersonationPolicy)
                    {
                        if (sc.WindowsIdentity != null)
                        {
                            switcher.wic = sc.WindowsIdentity.Impersonate(ref stackMark);
                        }
                        else if ((((flow & SecurityContextDisableFlow.WI) == SecurityContextDisableFlow.Nothing) && (prevSecurityContext != null)) && (prevSecurityContext.WindowsIdentity != null))
                        {
                            switcher.wic = System.Security.Principal.WindowsIdentity.SafeRevertToSelf(ref stackMark);
                        }
                    }
                    switcher.cssw = System.Threading.CompressedStack.SetCompressedStack(sc.CompressedStack, (prevSecurityContext != null) ? prevSecurityContext.CompressedStack : null);
                }
                catch
                {
                    switcher.UndoNoThrow();
                    throw;
                }
            }
            return(switcher);
        }
 internal static bool CurrentlyInDefaultFTSecurityContext(System.Threading.ExecutionContext threadEC)
 {
     return(IsDefaultThreadSecurityInfo() && (GetCurrentWI(threadEC) == null));
 }
Example #36
0
 public Reader(ExecutionContext ec)
 {
     m_ec = ec;
 }
Example #37
0
 internal static void Run(ExecutionContext executionContext, ContextCallback callback, Object state, bool preserveSyncCtx)
 {
     RunInternal(executionContext, callback, state, preserveSyncCtx);
 }
Example #38
0
        [HandleProcessCorruptedStateExceptions]             //
#endif // FEATURE_CORRUPTING_EXCEPTIONS
        internal static ExecutionContextSwitcher SetExecutionContext(ExecutionContext executionContext, bool preserveSyncCtx)
        {
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK

            Contract.Assert(executionContext != null);
            Contract.Assert(executionContext != s_dummyDefaultEC);

            // Set up the switcher object to return;
            ExecutionContextSwitcher ecsw = new ExecutionContextSwitcher();

            Thread currentThread            = Thread.CurrentThread;
            ExecutionContext.Reader outerEC = currentThread.GetExecutionContextReader();

            ecsw.thread  = currentThread;
            ecsw.outerEC = outerEC;
            ecsw.outerECBelongsToScope = currentThread.ExecutionContextBelongsToCurrentScope;

            if (preserveSyncCtx)
            {
                executionContext.SynchronizationContext = outerEC.SynchronizationContext;
            }
            executionContext.SynchronizationContextNoFlow = outerEC.SynchronizationContextNoFlow;

            currentThread.SetExecutionContext(executionContext, belongsToCurrentScope: true);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
                //set the security context
                SecurityContext sc = executionContext.SecurityContext;
                if (sc != null)
                {
                    // non-null SC: needs to be set
                    SecurityContext.Reader prevSeC = outerEC.SecurityContext;
                    ecsw.scsw = SecurityContext.SetSecurityContext(sc, prevSeC, false, ref stackMark);
                }
                else if (!SecurityContext.CurrentlyInDefaultFTSecurityContext(ecsw.outerEC))
                {
                    // null incoming SC, but we're currently not in FT: use static FTSC to set
                    SecurityContext.Reader prevSeC = outerEC.SecurityContext;
                    ecsw.scsw = SecurityContext.SetSecurityContext(SecurityContext.FullTrustSecurityContext, prevSeC, false, ref stackMark);
                }
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
#if FEATURE_CAS_POLICY
                // set the Host Context
                HostExecutionContext hostContext = executionContext.HostExecutionContext;
                if (hostContext != null)
                {
                    ecsw.hecsw = HostExecutionContextManager.SetHostExecutionContextInternal(hostContext);
                }
#endif // FEATURE_CAS_POLICY
            }
            catch
            {
                ecsw.UndoNoThrow();
                throw;
            }
            return(ecsw);
        }
Example #39
0
        [System.Security.SecurityCritical]  // auto-generated
        static internal ExecutionContext Capture(ref StackCrawlMark stackMark, CaptureOptions options)
        {
            ExecutionContext.Reader ecCurrent = Thread.CurrentThread.GetExecutionContextReader();

            // check to see if Flow is suppressed
            if (ecCurrent.IsFlowSuppressed)
            {
                return(null);
            }

            //
            // Attempt to capture context.  There may be nothing to capture...
            //

#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            // capture the security context
            SecurityContext secCtxNew = SecurityContext.Capture(ecCurrent, ref stackMark);
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
#if FEATURE_CAS_POLICY
            // capture the host execution context
            HostExecutionContext hostCtxNew = HostExecutionContextManager.CaptureHostExecutionContext();
#endif // FEATURE_CAS_POLICY

#if FEATURE_SYNCHRONIZATIONCONTEXT
            SynchronizationContext syncCtxNew = null;
#endif
            LogicalCallContext logCtxNew = null;

            if (!ecCurrent.IsNull)
            {
#if FEATURE_SYNCHRONIZATIONCONTEXT
                // capture the [....] context
                if (0 == (options & CaptureOptions.IgnoreSyncCtx))
                {
                    syncCtxNew = (ecCurrent.SynchronizationContext == null) ? null : ecCurrent.SynchronizationContext.CreateCopy();
                }
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT

                // copy over the Logical Call Context
                if (ecCurrent.LogicalCallContext.HasInfo)
                {
                    logCtxNew = ecCurrent.LogicalCallContext.Clone();
                }
            }

            //
            // If we didn't get anything but defaults, and we're allowed to return the
            // dummy default EC, don't bother allocating a new context.
            //
            if (0 != (options & CaptureOptions.OptimizeDefaultCase) &&
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
                secCtxNew == null &&
#endif
#if FEATURE_CAS_POLICY
                hostCtxNew == null &&
#endif // FEATURE_CAS_POLICY
#if FEATURE_SYNCHRONIZATIONCONTEXT
                syncCtxNew == null &&
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT
                (logCtxNew == null || !logCtxNew.HasInfo))
            {
                return(s_dummyDefaultEC);
            }

            //
            // Allocate the new context, and fill it in.
            //
            ExecutionContext ecNew = new ExecutionContext();
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            ecNew.SecurityContext = secCtxNew;
            if (ecNew.SecurityContext != null)
            {
                ecNew.SecurityContext.ExecutionContext = ecNew;
            }
#endif
#if FEATURE_CAS_POLICY
            ecNew._hostExecutionContext = hostCtxNew;
#endif // FEATURE_CAS_POLICY
#if FEATURE_SYNCHRONIZATIONCONTEXT
            ecNew._syncContext = syncCtxNew;
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT
            ecNew.LogicalCallContext = logCtxNew;
            ecNew.isNewCapture       = true;

            return(ecNew);
        }
Example #40
0
 // SynchronizationContext для ExecutionContext
 public static Sctx GetSyncCtx(this Ectx x)
 {
     return(__get(x));
 }
Example #41
0
        public static bool IsFlowSuppressed()
        {
            ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;

            return(executionContext != null && executionContext.m_isFlowSuppressed);
        }
Example #42
0
        // Direct copy of the above RunInternal overload, except that it passes the state into the callback strongly-typed and by ref.
        internal static void RunInternal <TState>(ExecutionContext executionContext, ContextCallback <TState> callback, ref TState state)
        {
            // Note: ExecutionContext.RunInternal is an extremely hot function and used by every await, ThreadPool execution, etc.
            // Note: Manual enregistering may be addressed by "Exception Handling Write Through Optimization"
            //       https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/eh-writethru.md

            // Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack
            // Capture references to Thread Contexts
            Thread           currentThread0        = Thread.CurrentThread;
            Thread           currentThread         = currentThread0;
            ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext;

            if (previousExecutionCtx0 != null && previousExecutionCtx0.m_isDefault)
            {
                // Default is a null ExecutionContext internally
                previousExecutionCtx0 = null;
            }

            // Store current ExecutionContext and SynchronizationContext as "previousXxx".
            // This allows us to restore them and undo any Context changes made in callback.Invoke
            // so that they won't "leak" back into caller.
            // These variables will cross EH so be forced to stack
            ExecutionContext       previousExecutionCtx = previousExecutionCtx0;
            SynchronizationContext previousSyncCtx      = currentThread0.SynchronizationContext;

            if (executionContext != null && executionContext.m_isDefault)
            {
                // Default is a null ExecutionContext internally
                executionContext = null;
            }

            if (previousExecutionCtx0 != executionContext)
            {
                // Restore changed ExecutionContext
                currentThread0.ExecutionContext = executionContext;
                if ((executionContext != null && executionContext.HasChangeNotifications) ||
                    (previousExecutionCtx0 != null && previousExecutionCtx0.HasChangeNotifications))
                {
                    // There are change notifications; trigger any affected
                    OnValuesChanged(previousExecutionCtx0, executionContext);
                }
            }

            ExceptionDispatchInfo edi = null;

            try
            {
                callback.Invoke(ref state);
            }
            catch (Exception ex)
            {
                // Note: we have a "catch" rather than a "finally" because we want
                // to stop the first pass of EH here.  That way we can restore the previous
                // context before any of our callers' EH filters run.
                edi = ExceptionDispatchInfo.Capture(ex);
            }

            // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
            SynchronizationContext previousSyncCtx1 = previousSyncCtx;
            Thread currentThread1 = currentThread;

            // The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
            if (currentThread1.SynchronizationContext != previousSyncCtx1)
            {
                // Restore changed SynchronizationContext back to previous
                currentThread1.SynchronizationContext = previousSyncCtx1;
            }

            ExecutionContext previousExecutionCtx1 = previousExecutionCtx;
            ExecutionContext currentExecutionCtx1  = currentThread1.ExecutionContext;

            if (currentExecutionCtx1 != previousExecutionCtx1)
            {
                // Restore changed ExecutionContext back to previous
                currentThread1.ExecutionContext = previousExecutionCtx1;
                if ((currentExecutionCtx1 != null && currentExecutionCtx1.HasChangeNotifications) ||
                    (previousExecutionCtx1 != null && previousExecutionCtx1.HasChangeNotifications))
                {
                    // There are change notifications; trigger any affected
                    OnValuesChanged(currentExecutionCtx1, previousExecutionCtx1);
                }
            }

            // If exception was thrown by callback, rethrow it now original contexts are restored
            edi?.Throw();
        }
Example #43
0
 internal static void RunForThreadPoolUnsafe <TState>(ExecutionContext executionContext, Action <TState> callback, in TState state)
Example #44
0
 public void Start()
 {
     _executionContext = ExecutionContext.Capture();
     StartInternal(this);
 }
Example #45
0
 internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
 {
     this._ioCompletionCallback = ioCompletionCallback;
     this._executionContext     = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
 }
Example #46
0
 internal void SetExecutionContextHelper(ExecutionContext ec)
 {
     _executionContext = ec;
 }
Example #47
0
 internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ExecutionContext executionContext)
 {
     _ioCompletionCallback = ioCompletionCallback;
     _executionContext     = executionContext;
 }