本文共 990 字,大约阅读时间需要 3 分钟。
/********************************************************************** * 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 } }
转载地址:http://jfxpo.baihongyu.com/