public static bool QueueUserWorkItem(WaitCallback callBack, object state)
        {
            if (callBack == null)
            {
                throw new ArgumentNullException("callBack");
            }

#if MOONLIGHT
            callBack = MoonlightHandler(callBack);
#endif
            if (callBack.IsTransparentProxy())
            {
                IAsyncResult ar = callBack.BeginInvoke(state, null, null);
                if (ar == null)
                {
                    return(false);
                }
            }
            else
            {
                if (!callBack.HasSingleTarget)
                {
                    throw new Exception("The delegate must have only one target");
                }

                AsyncResult ares = new AsyncResult(callBack, state, true);
                pool_queue(ares);
            }
            return(true);
        }
        public static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object state)
        {
            // no stack propagation here (that's why it's unsafe and requires extra security permissions)
            if (!callBack.IsTransparentProxy())
            {
                if (!callBack.HasSingleTarget)
                {
                    throw new Exception("The delegate must have only one target");
                }

                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);
        }
예제 #3
0
        public static bool QueueUserWorkItem(WaitCallback callBack, object state)
        {
            if (Microsoft.ThreadPool.UseMicrosoftThreadPool)
            {
                return(Microsoft.ThreadPool.QueueUserWorkItem(callBack, state));
            }
            else
            {
                if (callBack == null)
                {
                    throw new ArgumentNullException("callBack");
                }

                if (callBack.IsTransparentProxy())
                {
                    IAsyncResult ar = callBack.BeginInvoke(state, null, null);
                    if (ar == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    AsyncResult ares = new AsyncResult(callBack, state, true);
                    pool_queue(ares);
                }
                return(true);
            }
        }
예제 #4
0
 /// <summary>Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.</summary>
 /// <returns>true if the method is successfully queued; <see cref="T:System.NotSupportedException" /> is thrown if the work item could not be queued.</returns>
 /// <param name="callBack">A <see cref="T:System.Threading.WaitCallback" /> representing the method to execute. </param>
 /// <param name="state">An object containing data to be used by the method. </param>
 /// <exception cref="T:System.NotSupportedException">The common language runtime (CLR) is hosted, and the host does not support this action.</exception>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="callBack" /> is null.</exception>
 /// <filterpriority>1</filterpriority>
 public static bool QueueUserWorkItem(WaitCallback callBack, object state)
 {
     if (callBack == null)
     {
         throw new ArgumentNullException("callBack");
     }
     return(callBack.BeginInvoke(state, null, null) != null);
 }
예제 #5
0
        public static bool QueueUserWorkItem(WaitCallback callback, object state)
        {
            IAsyncResult ar = callback.BeginInvoke(state, null, null);

            if (ar == null)
            {
                return(false);
            }
            return(true);
        }
예제 #6
0
        public static bool QueueUserWorkItem(WaitCallback callBack, object state)
        {
            if (callBack == null)
            {
                throw new ArgumentNullException("callBack");
            }

#if NET_2_1 && !MONOTOUCH && !MICRO_LIB
            callBack = MoonlightHandler(callBack);
#endif
            IAsyncResult ar = callBack.BeginInvoke(state, null, null);
            if (ar == null)
            {
                return(false);
            }
            return(true);
        }
예제 #7
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);
        }
예제 #8
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);
            }
        }
예제 #9
0
 public void FireAndForget(System.Threading.WaitCallback callback, object obj)
 {
     callback.BeginInvoke(obj, EndFireAndForget, callback);
 }
예제 #10
0
 public void FireAndForget(System.Threading.WaitCallback callback)
 {
     callback.BeginInvoke(null, EndFireAndForget, callback);
 }