DotNetWorkQueue.Queue.StopThread.TryForceTerminate C# (CSharp) Method

TryForceTerminate() public method

Stops a thread by aborting it if configured to do; otherwise it will wait (forever if needed) until the thread dies.
public TryForceTerminate ( Thread workerThread ) : bool
workerThread System.Threading.Thread The worker thread.
return bool
        public bool TryForceTerminate(Thread workerThread)
        {
            if (_abortWorkerThread.Abort(workerThread)) return true;

            //wait for the thread to exit
            _waitForThreadToFinish.Wait(workerThread);

            return true;
        }
    }

Usage Example

        /// <summary>
        /// Tries to force terminate the thread if needed
        /// </summary>
        public override void TryForceTerminate()
        {
            if (!Running)
            {
                return;
            }

            AttemptToTerminate(); //one last request to terminate without an abort or a spin and wait

            if (WorkerThread == null || !WorkerThread.IsAlive)
            {
                return;
            }

            StopThread.TryForceTerminate(WorkerThread);
        }