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执行任务时会从线程池中获取空闲的线程。
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执行任务时会从线程池中获取空闲的线程。