C#相关的线程

Posted on 2018-08-12 22:41  yacbo  阅读(125)  评论(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执行任务时会从线程池中获取空闲的线程。

Copyright © 2024 yacbo
Powered by .NET 8.0 on Kubernetes