Esempio n. 1
0
        public static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object state)
        {
            // no stack propagation here (that's why it's unsafe and requires extra security permissions)
            IAsyncResult ar = null;

            try {
                if (!ExecutionContext.IsFlowSuppressed())
                {
                    ExecutionContext.SuppressFlow();                      // on current thread only
                }
                ar = callBack.BeginInvoke(state, null, null);
            }
            finally {
                if (ExecutionContext.IsFlowSuppressed())
                {
                    ExecutionContext.RestoreFlow();
                }
            }
            return(ar != null);
        }
Esempio n. 2
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);
            }
        }