private static void tt2()
{
Task task = null;
for (int i = 0; i < 10; i++)
{
task = Task.Factory.StartNew(callback, i);
}
Thread.Sleep(10000000);
}
private static void callback(object i)
{
Console.WriteLine("任务"+i.ToString()+"开始-执行");
Thread.Sleep(10000);
Console.WriteLine("任务" + i.ToString() + "结束");
}
或者
private static void tt3()
{
for (int i = 0; i < 10; i++)
{
Task task = new Task(callback, i);
task.Start();
}
Thread.Sleep(10000000);
}
private static void callback(object i)
{
Console.WriteLine("任务"+i.ToString()+"开始-执行");
Thread.Sleep(10000);
Console.WriteLine("任务" + i.ToString() + "结束");
}
执行截图