Platinum Partner

"Extend" The Thread Class In Csharp

//just inherit from the EasyThread class and override the PerformWork method

   public class EasyThread: IDisposable
    {
        Thread WorkerThread;
        public EasyThread()
        {
            if (WorkerThread == null)
                WorkerThread = new Thread(new ThreadStart(PerformWork));
        }


        public void Run()
        {
            if (WorkerThread.IsAlive == false)
                WorkerThread.Start();

            if (WorkerThread.ThreadState == ThreadState.Suspended)
                WorkerThread.Resume();
        }

        /// 
        /// EasyThread provides a facade to inheriting from a Thread class.
        /// Override the perform work method to perform your tasks.
        /// 
        protected virtual void PerformWork()
        {

        }

        public void Pause()
        {
            WorkerThread.Suspend();
        }

        public void Quit()
        {
            Cleanup();
        }

        private void Cleanup()
        {
            WorkerThread.Join(0);
            WorkerThread = null;
        }

        public void Dispose()
        {
            Cleanup();
        }
    }
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}