/// <summary> /// Loop, executing targets as they are received. /// </summary> public override void Run() { bool ran = false; while (run) { try { lock (lockObject) { while (runnable == null && run) { Monitor.Wait(lockObject, 500); } if (runnable != null) { ran = true; runnable.Run(); } } } catch (Exception exceptionInRunnable) { log.Error("Error while executing the IRunnable: ", exceptionInRunnable); } finally { lock (lockObject) { runnable = null; } // repair the thread in case the runnable mucked it up... Priority = tp.ThreadPriority; if (runOnce) { run = false; tp.ClearFromBusyWorkersList(this); } else if (ran) { ran = false; tp.MakeAvailable(this); } } } log.Debug("WorkerThread is shut down"); }
/// <summary> /// Loop, executing targets as they are received. /// </summary> public override void Run() { bool ran = false; bool shouldRun; lock (this) { shouldRun = run; } while (shouldRun) { try { lock (this) { while (runnable == null && run) { Monitor.Wait(this, 500); } if (runnable != null) { ran = true; runnable.Run(); } } } catch (Exception) { } finally { lock (this) { runnable = null; } // repair the thread in case the runnable mucked it up... if (Priority != tp.ThreadPriority) { Priority = tp.ThreadPriority; } if (runOnce) { lock (this) { run = false; } tp.ClearFromBusyWorkersList(this); } else if (ran) { ran = false; tp.MakeAvailable(this); } } // read value of run within synchronized block to be // sure of its value lock (this) { shouldRun = run; } } }