你的位置:首页 > ASP.net教程

[ASP.net教程]关于Task类


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() + "结束");    }

执行截图

)T$`L4R@%E)5351G}49V2LH