/// <summary> /// Queues a method for execution. The method executes /// when a thread pool thread becomes available. /// </summary> /// <param name="start">A delegate specifying which method to run /// when the <see cref="Thread"/> is started.</param> /// <returns>Returns true if the method is successfully queued.</returns> public static bool EnqueueOnThreadPool(ThreadStart start) { ConnectionScope scope = ConnectionScope.Current; return(ThreadPool.QueueUserWorkItem(delegate(object state) { ConnectionScope.Copy(scope); start(); }, null)); }
/// <summary> /// Queues a method for execution. The method executes /// when a thread pool thread becomes available. /// </summary> /// <param name="start">A delegate specifying which method to run /// when the <see cref="Thread"/> is started.</param> /// <param name="state">An object containing data to be used by the method.</param> /// <returns>Returns true if the method is successfully queued.</returns> public static bool EnqueueOnThreadPool(ParameterizedThreadStart start, object state) { ConnectionScope scope = ConnectionScope.Current; return(ThreadPool.QueueUserWorkItem(delegate(object originalState) { ConnectionScope.Copy(scope); start(originalState); }, state)); }
/// <summary> /// Creates a new <see cref="Thread"/> object and copies /// the current <see cref="ConnectionScope"/> parameters. /// </summary> /// <param name="start">A delegate specifying which method to run /// when the <see cref="Thread"/> is started.</param> /// <returns>Returns a new <see cref="Thread"/> object.</returns> public static Thread NewThread(ThreadStart start) { ConnectionScope scope = ConnectionScope.Current; Thread t = new Thread(delegate() { ConnectionScope.Copy(scope); start(); }); return(t); }
/// <summary> /// Creates a new <see cref="Thread"/> object and copies /// the current <see cref="ConnectionScope"/> parameters. /// </summary> /// <param name="start">A delegate specifying which method to run /// when the <see cref="Thread"/> is started.</param> /// <returns>Returns a new <see cref="Thread"/> object.</returns> public static Thread NewThread(ParameterizedThreadStart start) { ConnectionScope scope = ConnectionScope.Current; Thread t = new Thread(delegate(Object obj) { ConnectionScope.Copy(scope); start(obj); }); return(t); }