简体   繁体   English

关闭应用程序时是否需要终止线程?

[英]Is it necessary to terminate the threads when closing the application?

当我的应用程序即将关闭时,UI线程是否应该“告诉”其他线程终止,并在关闭应用程序之前等待它们终止?

To clarify; 澄清; when your main thread (the one that started with your process) returns from the WinMain function, the process will exit and all your other threads will terminate automatically. 当您的主线程(从进程开始的线程)从WinMain函数返回时,该进程将退出,而所有其他线程将自动终止。

It depends what your other threads are doing as to how important it is that you shut them down cleanly. 完全关闭它们取决于您其他线程在做什么。

For example, if the other threads are potentially writing to disk, then you absolutely should shut them down cleanly. 例如,如果其他线程可能正在写入磁盘,则绝对应该干净地关闭它们。 If they're just doing calculations then it probably wouldn't hurt to let them die automatically when your main thread exits. 如果他们只是在进行计算,那么当您的主线程退出时让它们自动死亡可能不会受到伤害。

However it's always good programming practice to clean up after yourself (free any memory allocations, etc). 但是,清理自己(释放任何内存分配等)总是一种好的编程习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM