C# 多线程

/**********************************************************************
 *                           C# 多线程
 * 说明:
 *     在上位机的编码中多线程是很常用的方式,网络编程中更是常用。
 *
 *                                  2016-12-9 深圳 南山平山村 曾剑锋
 *********************************************************************/

一、参考文档:
    Unable to inherit from a Thread Class in C# ?
        http://stackoverflow.com/questions/8123461/unable-to-inherit-from-a-thread-class-in-c-sharp

二、解决方法:
    abstract class BaseThread
    {
        private Thread _thread;

        protected BaseThread() { _thread = new Thread(new ThreadStart(this.RunThread)); }

        // Thread methods / properties
        public void Start() { _thread.Start(); }
        public void Join() { _thread.Join(); }
        public bool IsAlive { get { return _thread.IsAlive; } }

        // Override in base class
        public abstract void RunThread();
    }

    public MyThread : BaseThread
    {
        public override void RunThread() {
            // Do some stuff
        }
    }

 

posted on 2016-12-09 15:26  zengjf  阅读(314)  评论(0编辑  收藏  举报

导航