Beispiel #1
0
            /// <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();
                            }
                        }
                    }
                    catch (Exception exceptionInRunnable)
                    {
                        log.ErrorException("Error while executing the Runnable: " + exceptionInRunnable.Message, exceptionInRunnable);
                    }
                    finally
                    {
                        lock (lockObject)
                        {
                            runnable = null;
                        }
#if THREAD_PRIORITY
                        // repair the thread in case the runnable mucked it up...
                        Priority = tp.ThreadPriority;
#endif // THREAD_PRIORITY

                        if (runOnce)
                        {
                            run = false;
                            tp.ClearFromBusyWorkersList(this);
                        }
                        else if (ran)
                        {
                            ran = false;
                            tp.MakeAvailable(this);
                        }
                    }
                }

                log.Debug("WorkerThread is shut down");
            }
            public override void Run()
            {
                bool running = false;

                while (canRun)
                {
                    try
                    {
                        lock (lockObject)
                        {
                            while (runnable == null && canRun)
                            {
                                Monitor.Wait(lockObject, 500);
                            }
                            if (runnable != null)
                            {
                                running = true;
                                runnable.Run();
                            }
                        }
                    }
                    catch (Exception exceptionInRunnable)
                    {
                        log.Error("Error while executing the Runnable: ", exceptionInRunnable);
                    }
                    finally
                    {
                        lock (lockObject)
                        {
                            runnable = null;
                        }
                        // repair the thread in case the runnable mucked it up...
                        Priority = tp.ThreadPriority;

                        if (runOnce)
                        {
                            canRun = false;
                            tp.ClearFromBusyWorkersList(this);
                        }
                        else if (running)
                        {
                            running = false;
                            tp.MakeAvailable(this);
                        }
                    }
                }

                log.Debug("WorkerThread is shut down");
            }
Beispiel #3
0
            /// <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;
                    }
                }
            }
Beispiel #4
0
            /// <summary>
            /// Loop, executing targets as they are received.
            /// </summary>
            public override void Run()
            {
                var  ran = false;
                bool runOnce;
                bool shouldRun;

                lock (this)
                {
                    runOnce   = (runnable != null);
                    shouldRun = run;
                }

                while (shouldRun)
                {
                    try
                    {
                        lock (this)
                        {
                            while (runnable == null && run)
                            {
                                Monitor.Wait(this, 500);
                            }
                        }

                        if (runnable != null)
                        {
                            ran = true;
                            runnable.Run();
                        }
                    }
                    catch (Exception exceptionInRunnable)
                    {
                        Log.Error("Error while executing the Runnable: ", exceptionInRunnable);
                    }
                    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;
                            }
                        }
                        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;
                    }
                }


                Log.Debug("WorkerThread is shutting down");
            }