线程开启方式2—任务

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading;
 6 using System.Threading.Tasks;
 7 
 8 namespace 线程开启4_任务
 9 {
10     class Program
11     {
12 
13         private static void taskMethod()
14         {
15             Console.WriteLine("任务开始");
16             Thread.Sleep(3000);//任务暂停3秒钟
17             Console.WriteLine("任务结束!");
18         }
19 
20         static void Main(string[] args)
21         {
22             Task t=new Task(taskMethod);//创建一个新线程,传递一个方法
23             t.Start();//开始新线程
24             Console.ReadKey();
25         }
26     }
27 }

 

posted on 2015-12-23 20:22  pnzpb  阅读(122)  评论(0编辑  收藏  举报

导航