关闭窗口后,为什么进程仍处于后台 [英] why the process still in background after I close the window

查看:111
本文介绍了关闭窗口后,为什么进程仍处于后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在QT中构建​​一个程序,我通过单击X按钮关闭窗口后发现该过程仍处于后台。



我的析构函数中的代码很少。

I'm building a program in QT, I found that the process still in background after I close the window by click the 'X' button.

Just little code in my destructor function.

推荐答案

因为你的进程没有终止;执行没有离开入口点(主)功能。为什么?因为您的代码中存在一些错误。该怎么办?修复该错误。



信息不足?那么,这个答案比你的问题更有用。 :-)



-SA
Because your process is not terminated; the execution did not leave entry point (main) function. Why? Because of some bug in your code. What to do? Fix that bug.

Not enough information? Well, this answer is more informative than your question. :-)

—SA


非常感谢,我已经解决了这个问题。



我没有取消注册我写的线程。
Thank you very much, I have solve this problem.

I have not unregistor a watching thread that I wrote.


[补充答案,在OP澄清之后:]



在解决方案帖子中,OP提到一些额外的线程不允许整个进程终止。这是非常常见的原因。


只有一条建议:在关闭主窗口之前终止所有线程是最好的主意。这样,您就可以完全控制导致问题的线程终止的时间。但是,在某些简单的情况下,当这种操作的顺序不是必需的时候,你可以通过使一个有问题的线程成为后台线程来简化它(名称背景真的是误导性的)。它的主要区别是:后台线程不会阻止整个进程终止;最终。这样的线程将自动终止。使用此属性: http:// msdn。 microsoft.com/en-us/library/system.threading.thread.isbackground%28v=vs.110%29.aspx [ ^ ]。



再次注意:当后台线程自动终止时,你不能做出任何假设,如果你以某种方式依赖于它,可能会产生一些问题:需要完成某些操作,等待某些其他线程上的线程终止,依此类推。



-SA
[Additional answer, after OP's clarification:]

In the "solution" post, OP mentioned that some additional thread does not allow the whole process to terminate. This is the very usual reason.

Just one advice: terminating all the threads before closing main window is the best idea. This way, you can have a full control of the time of termination of abortion of the thread causing the problem. However, in some simple cases when the order of such action is not essential, you can simplify it by making a thread in question a background thread (the name "background" is really misleading). The major difference it makes is: background thread does not prevent the whole process from termination; eventually. such threads will be terminated automatically. Use this property: http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground%28v=vs.110%29.aspx[^].

Again, be careful: you cannot make any assumption when the background thread is automatically terminated, which can create some problems if you somehow rely on that: need to finalize some action, wait for thread termination on some other thread, and so on.

—SA


这篇关于关闭窗口后,为什么进程仍处于后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆