public void RunThread (ThreadInfo tinfo) { lock (this) { PoolLog.Debug ("Thread {0}: got new worker", id); this.tinfo = tinfo; Monitor.Pulse (this); } } private void WorkerLoop () { while (running) { lock (this) { if (tinfo.Equals (ThreadInfo.Zero)) { PoolLog.Debug ("Thread {0}: waiting on job...", id); Monitor.Wait (this); } if (!running) { PoolLog.Debug ("Thread {0}: terminating", id); break; } // set the principal if (tinfo.Principal != null) { Thread.CurrentPrincipal = tinfo.Principal; } try { PoolLog.Debug ("Thread {0}: running job...", id); if (tinfo.ThreadStart != null) { tinfo.ThreadStart (); } else { tinfo.WaitCallback (tinfo.UserData); } } catch (Exception e) { log.Info ("Unhandled exception: " + e); } finally { PoolLog.Debug ("Thread {0}: job finished", id); tinfo = ThreadInfo.Zero; finishTime = DateTime.Now; if (Finished != null) Finished (this, new EventArgs ()); } } } }