我们先从最基础的Thread说起。

 

创建并启动线程

创建并启动一个线程,如下代码:

多线程(2)Thread

 1 namespace ConsoleApplication17
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             var thread = new Thread(PrintNumbers);
 8             thread.Start();
 9 
10             Console.WriteLine("Thread Start...");
11             Console.ReadKey();
12         }
13 
14         /// <summary>
15         /// 匹配委托的方法
16         /// </summary>
17         public static void PrintNumbers()
18         {
19             Console.WriteLine("Starting......");
20             for (int i = 0; i < 10; i++)
21             {
22                 Console.WriteLine(i);
23             }
24         }
25     }
26 }
View Code

相关文章:

  • 2021-07-21
  • 2021-05-22
  • 2021-08-28
  • 2021-12-01
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
猜你喜欢
  • 2021-05-12
  • 2022-01-26
  • 2021-09-27
  • 2021-12-13
  • 2021-11-25
相关资源
相似解决方案