C#線程類的定義實(shí)例解析
作者:nokiaguy
C#線程類的定義是如何實(shí)現(xiàn)的呢?這里我們通過使用Thread類的操作來向你講述C#線程類的定義等等內(nèi)容。
C#線程類的定義實(shí)例實(shí)現(xiàn)是如何的呢?我們使用Thread類,將Thread類封裝在一個(gè)MyThread類中,以使任何從MyThread繼承的類都具有多線程能力。MyThread類的代碼如下:
C#線程類的定義實(shí)例:
- //C#線程類的定義實(shí)例
- 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建立并運(yùn)行線程");
- }
- }
- static void Main(string[] args)
- {
- NewThread nt = new NewThread();
- nt.start();
- }
C#線程類的定義實(shí)例基本的內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)C#線程類的定義有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡
來源:
博客園