C#线程类的定义实例解析

C#线程类的定义实例实现是如何的呢?我们使用Thread类,将Thread类封装在一个MyThread类中,以使任何从MyThread继承的类都具有多线程能力。MyThread类的代码如下:

C#线程类的定义实例:

 
 
 
  1. //C#线程类的定义实例
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. namespace MyThread
  8. {
  9.    abstract class MyThread
  10.     {
  11.        Thread thread = null;
  12.        abstract public void run();
  13.         public void start()
  14.         {
  15.             if (thread == null)
  16.                 thread = new Thread(run);
  17.             thread.Start();
  18.         }
  19.     }
  20. }

C#线程类的定义之使用MyThread类:

 
 
 
  1. class NewThread : MyThread
  2. {
  3.       override public void run()
  4.       {
  5.       Console.WriteLine("使用MyThread建立并运行线程");
  6.       }
  7.   }
  8.   static void Main(string[] args)
  9.   {
  10.       NewThread nt = new NewThread();
  11.       nt.start();
  12.   }

C#线程类的定义实例基本的内容就向你介绍到这里,希望对你了解和学习C#线程类的定义有所帮助。


网页题目:C#线程类的定义实例解析
分享URL:http://gydahua.com/article/cogegid.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流