RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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://jxjierui.cn/article/cogegid.html