Example #1
0
        void ThreadLoop()
        {
            var keepRunning = true;

            while (keepRunning)
            {
                System.Threading.Thread.Sleep(10);
                switch (m_Thread.ThreadState)
                {
                case System.Threading.ThreadState.Aborted:
                case System.Threading.ThreadState.AbortRequested:
                case System.Threading.ThreadState.Stopped:
                case System.Threading.ThreadState.StopRequested:
                    keepRunning = false;
                    break;
                }

                AbstractThreadJob job = null;

                lock (m_ThreadJobs)
                {
                    if (m_ThreadJobs.Count == 0)
                    {
                        continue;
                    }

                    job = m_ThreadJobs[0];
                    m_ThreadJobs.RemoveAt(0);
                }

                job.state = AbstractThreadJob.State.Running;
                try
                {
                    m_Repaint = true;
                    job.ThreadFunc();
                }
                catch (System.Threading.ThreadAbortException e)
                {
                    throw e;
                }
                catch (System.Exception e)
                {
                    m_Exceptions.Add(e);
                }
                finally
                {
                    m_Repaint = true;
                    job.state = AbstractThreadJob.State.Completed;
                }

                lock (m_IntegrationJobs)
                {
                    m_IntegrationJobs.Add(job);
                }
            }
        }
        void ThreadLoop()
        {
            while (!isClosing)
            {
                AbstractThreadJob job = null;

                lock (m_ThreadJobs)
                {
                    while (m_ThreadJobs.Count == 0)
                    {
                        Monitor.Wait(m_ThreadJobs); // block myself, waiting for jobs
                        if (isClosing)
                        {
                            return; // exit
                        }
                    }

                    job = m_ThreadJobs[0];
                    m_ThreadJobs.RemoveAt(0);
                }

                job.state = AbstractThreadJob.State.Running;
                try
                {
                    m_Repaint = true;
                    job.ThreadFunc();
                }
                catch (System.Threading.ThreadAbortException e)
                {
                    throw e;
                }
                catch (System.Exception e)
                {
                    m_Exceptions.Add(e);
                }
                finally
                {
                    m_Repaint = true;
                    job.state = AbstractThreadJob.State.Completed;
                }

                lock (m_IntegrationJobs)
                {
                    m_IntegrationJobs.Add(job);
                }
            }
        }