public void Stop(int timeoutInMs) { if (theThread != null) { threadShouldStop = true; threadTrigger.Release(); if (theStoppingDelegate != null) { theStoppingDelegate.Invoke(); } if (!threadEnd.Wait(timeoutInMs)) { theThread.Abort(); } } }
private void StartThreadExecute() { int timeoutValue = threadTimeoutInMs; threadStart.Release(); running = true; while (!threadShouldStop) { try { theRuntimeDelegate.Invoke(); if (timeoutValue > 0) { threadTrigger.Wait(timeoutValue); } if (threadShouldStop) { break; } } catch (ThreadAbortException ex) { Thread.ResetAbort(); break; } catch (Exception) { if (recoverable && !threadShouldStop) { Thread.Sleep(100); } else { break; } } } threadEnd.Release(); running = false; }
private void Start() { action.Invoke(); }