Esempio n. 1
0
        public void Undo()
        {
            if (_t == null)
            {
                throw new InvalidOperationException(Locale.GetText(
                                                        "Can only be called once."));
            }
            switch (_type)
            {
            case AsyncFlowControlType.Execution:
                ExecutionContext.RestoreFlow();
                break;

            case AsyncFlowControlType.Security:
                        #if !DISABLE_SECURITY
                SecurityContext.RestoreFlow();
                        #endif
                break;
            }
            _t = null;
        }
        /// <summary>Restores the flow of the execution context between threads.</summary>
        /// <exception cref="T:System.InvalidOperationException">The <see cref="T:System.Threading.AsyncFlowControl" /> structure is not used on the thread where it was created.-or-The <see cref="T:System.Threading.AsyncFlowControl" /> structure has already been used to call <see cref="M:System.Threading.AsyncFlowControl.Undo" />.</exception>
        /// <filterpriority>2</filterpriority>
        public void Undo()
        {
            if (this._t == null)
            {
                throw new InvalidOperationException(Locale.GetText("Can only be called once."));
            }
            AsyncFlowControlType type = this._type;

            if (type != AsyncFlowControlType.Execution)
            {
                if (type == AsyncFlowControlType.Security)
                {
                    SecurityContext.RestoreFlow();
                }
            }
            else
            {
                ExecutionContext.RestoreFlow();
            }
            this._t = null;
        }
Esempio n. 3
0
        public static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object state)
        {
            if (Microsoft.ThreadPool.UseMicrosoftThreadPool)
            {
                return(Microsoft.ThreadPool.UnsafeQueueUserWorkItem(callBack, state));
            }
            else
            {
                if (callBack == null)
                {
                    throw new ArgumentNullException("callBack");
                }

                // no stack propagation here (that's why it's unsafe and requires extra security permissions)
                if (!callBack.IsTransparentProxy())
                {
                    AsyncResult ares = new AsyncResult(callBack, state, false);
                    pool_queue(ares);
                    return(true);
                }
                try {
                    if (!ExecutionContext.IsFlowSuppressed())
                    {
                        ExecutionContext.SuppressFlow();                          // on current thread only
                    }
                    IAsyncResult ar = callBack.BeginInvoke(state, null, null);
                    if (ar == null)
                    {
                        return(false);
                    }
                } finally {
                    if (ExecutionContext.IsFlowSuppressed())
                    {
                        ExecutionContext.RestoreFlow();
                    }
                }
                return(true);
            }
        }