C#线程类的定义实例解析
C#线程类的定义实例实现是如何的呢?我们使用Thread类,将Thread类封装在一个MyThread类中,以使任何从MyThread继承的类都具有多线程能力。MyThread类的代码如下:
C#线程类的定义实例:
- //C#线程类的定义实例
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace MyThread
- {
- abstract class MyThread
- {
- Thread thread = null;
- abstract public void run();
- public void start()
- {
- if (thread == null)
- thread = new Thread(run);
- thread.Start();
- }
- }
- }
C#线程类的定义之使用MyThread类:
- class NewThread : MyThread
- {
- override public void run()
- {
- Console.WriteLine("使用MyThread建立并运行线程");
- }
- }
- static void Main(string[] args)
- {
- NewThread nt = new NewThread();
- nt.start();
- }
C#线程类的定义实例基本的内容就向你介绍到这里,希望对你了解和学习C#线程类的定义有所帮助。
【编辑推荐】
- C#静态类和静态类成员详解
- C# byte数组常用扩展浅析
- 浅析C#byte数组转化成图像的实现
- C#线程概述及视图解析
- C#线程操作常见的六大操作方法
版权声明:
作者:后浪云
链接:https://www.idc.net/help/406310/
文章版权归作者所有,未经允许请勿转载。
THE END