前面一段时间,一直在看<<C#高级编程>>第七版线程、任务和同步这一章的知识。创建线程,除了前面介绍的使用委托创建线程之外,创建线程的第二种方式是使用Thread类创建线程。

1.创建线程

使用Thread类可以创建和控制线程。下面的代码是创建和启动一个新线程的简单例子。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
   6:  
namespace Threading
   8: {
class Program
  10:     {
string[] args)
  12:        {
//Thread类的构造函数重载为接受ThreadStart和ParameterizedThreadStart类型的委托参数
new Thread(ThreadMain);
  15:            t1.Start();
);
  17:        }
  18:        
//ThreadStart委托定义了一个返回类型为void的无参数方法
void ThreadMain()
  21:        {
);
  23:        }
  24:      }
  25: }

相关文章:

  • 2021-06-27
  • 2019-07-06
  • 2022-01-22
  • 2022-02-09
  • 2022-12-23
  • 2021-12-11
  • 2018-09-06
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-10-29
  • 2021-09-11
相关资源
相似解决方案