public static bool QueueUserWorkItem(WaitCallback callBack, object state) { if (callBack == null) { throw new ArgumentNullException("callBack"); } 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); }
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, !ExecutionContext.IsFlowSuppressed()); pool_queue(ares); } return(true); } }
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); } }