且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.NET应用程序是否在终止程序之前等待所有前台线程完成?

更新时间:2022-02-16 23:14:22

我不好,我的眼睛看不到20-20.该程序确实等待生成的前台线程完成执行.

My bad, my eyes were not seeing 20-20. The program does indeed wait for the spawned foreground thread to complete execution.

发生的事情是,当我通过减小Times方法的整数接收器的值来减少迭代次数时,即使程序实际上已经完成了所有 Hello 的打印, ,在我看来,该程序仍在忙于打印.那使我相信生成的线程仍在运行,并且当我按下键盘上的任何其他键时,它立即终止了该过程.

What was happening was that when I reduced the number of iterations by decreasing the value of the integer receiver of the Times method, even when the program actually had finished printing all the Hello's, it appeared to my eyes that the program was still busy printing. That led me to believe that the spawned thread is still running its course, and when I pressed any other key on my keyboard, it immediately terminated the process.