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