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://www.hantingmc.com/qtweb/news8/362308.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联