class Program
{
static void Test()
{
for (int i = 0; i < 1000; i++)
{
Console.Write("A ");
}
}
static void FirstDownload()
{
Console.WriteLine("下载中。。。");
Thread.Sleep(2000);
}
static void SecondAlert(Task t)
{
Console.WriteLine("。。。下载完成");
Thread.Sleep(1000);
}
static void Main(string[] args)
{
#region 任务创建方法1
//TaskFactory tf = new TaskFactory();
//Task t = tf.StartNew(Test);
#endregion
#region 任务创建方法2
//Task t = new Task(Test);
//t.Start();
#endregion
#region 连续任务创建
Task t1 = new Task(FirstDownload);
Task t2 = t1.ContinueWith(SecondAlert);
Task t3 = t2.ContinueWith(SecondAlert);
t1.Start();
#endregion
Thread.Sleep(5000);
Console.Read();
}
}
C# 多任务—任务的创建
于 2022-03-25 00:18:09 首次发布