All pastes #47486 Raw Edit

Someone

public text v1 · immutable
#47486 ·published 2006-03-29 18:26 UTC
rendered paste body
        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 ());
                    }
                }
            }
        }