public static bool TryAbortAndFree(ref System.Threading.Thread thread, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped, int timeout = (int)Common.Extensions.TimeSpan.TimeSpanExtensions.MicrosecondsPerMillisecond) { try { AbortAndFree(ref thread, state, timeout); } catch { return(false); } return(object.ReferenceEquals(thread, null)); }
/// <summary> /// Does the thread have the state? /// </summary> public bool _hasState(System.Threading.ThreadState state) { System.Threading.Thread thread = this.Thread; if (null == thread) { return(false); } if ((thread.ThreadState & state) == state) { return(true); } else { return(false); } }
public static void AbortAndFree(ref System.Threading.Thread thread, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped, int timeout = (int)Common.Extensions.TimeSpan.TimeSpanExtensions.MicrosecondsPerMillisecond) { //If the worker IsAlive and has the requested state. if (thread != null && (thread.IsAlive && thread.ThreadState.HasFlag(state))) { //Attempt to join if (false == thread.Join(timeout)) { try { //Abort thread.Abort(); } catch (System.Threading.ThreadAbortException) { System.Threading.Thread.ResetAbort(); } catch { throw; } //Cancellation not supported } //Reset the state of the thread to indicate success thread = null; } }
public static Alt.Threading.ThreadState ToThreadState(System.Threading.ThreadState src) { switch (src) { case System.Threading.ThreadState.Running: return(Alt.Threading.ThreadState.Running); case System.Threading.ThreadState.StopRequested: return(Alt.Threading.ThreadState.StopRequested); case System.Threading.ThreadState.SuspendRequested: return(Alt.Threading.ThreadState.SuspendRequested); case System.Threading.ThreadState.Background: return(Alt.Threading.ThreadState.Background); case System.Threading.ThreadState.Unstarted: return(Alt.Threading.ThreadState.Unstarted); case System.Threading.ThreadState.Stopped: return(Alt.Threading.ThreadState.Stopped); case System.Threading.ThreadState.WaitSleepJoin: return(Alt.Threading.ThreadState.WaitSleepJoin); case System.Threading.ThreadState.Suspended: return(Alt.Threading.ThreadState.Suspended); case System.Threading.ThreadState.AbortRequested: return(Alt.Threading.ThreadState.AbortRequested); case System.Threading.ThreadState.Aborted: return(Alt.Threading.ThreadState.Aborted); } return(Alt.Threading.ThreadState.Unstarted); }
public static bool TryAbortAndFree(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped) { try { AbortAndFree(ref thread, timeout, state); } catch { return(false); } return(object.ReferenceEquals(thread, null)); }
public static bool TryAbort(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped) { try { Abort(ref thread, timeout, state); } catch { return(false); } return(thread == null); }
public static void Abort(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped) { //If the worker IsAlive and has the requested state. if (thread != null && (thread.IsAlive && thread.ThreadState.HasFlag(state))) { //Attempt to join if (false == thread.Join(timeout)) { try { //Abort thread.Abort(); } catch (System.Threading.ThreadAbortException) { System.Threading.Thread.ResetAbort(); } catch { throw; } //Cancellation not supported } //Reset the state of the thread to indicate success thread = null; } }