C#相关的线程

Posted on 2018-08-12 22:41  yacbo  阅读(126)  评论(0)    收藏  举报
for(int i =0;i<=5;i++)
{
    Thread th = new Thread(Dotaskfunction());
    th.Start();  
}
for(int i=0;i<=5;i++)
{
   Task.Run(()=>{Dotaskfunction();});
}

IsBackground(true); //前台程序退出后,后台程序也自动退出

Task是C#线程的一种实现方式,与thread的不同在于,task执行任务时会从线程池中获取空闲的线程。

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3