DotNetWorkQueue.Queue.WorkerTerminate.AttemptToTerminate C# (CSharp) Method

AttemptToTerminate() public method

Attempts to terminate the passed in thread
public AttemptToTerminate ( Thread workerThread, System.TimeSpan timeout ) : bool
workerThread Thread The worker thread.
timeout System.TimeSpan The timeout.
return bool
        public bool AttemptToTerminate(Thread workerThread, TimeSpan? timeout)
        {
            if (workerThread == null || !workerThread.IsAlive)
                return true; //if the thread is null or not alive, its terminated

            if (timeout.HasValue)
            {
                return workerThread.Join(timeout.Value);
            }
            workerThread.Join();
            return true;
        }
    }

Usage Example

Exemplo n.º 1
0
 /// <summary>
 /// Attempts to terminate the worker thread.
 /// </summary>
 /// <returns></returns>
 public virtual bool AttemptToTerminate()
 {
     return(_workerTerminate.AttemptToTerminate(WorkerThread, TimeSpan.Zero));
 }
WorkerTerminate