你怎么知道另一个程序何时闲置? [英] How do you tell when another program is idle?

查看:105
本文介绍了你怎么知道另一个程序何时闲置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个自动关机程序,只要用户下载或安装完东西,它就会关闭计算机。现在我遇到了麻烦,我尝试让程序读取过程关闭,但问题是大多数下载和软件安装在完成时不会自动退出,因此该方法不起作用。我的下一步是尝试让我的程序读取所选程序的闲置程序,我该怎么做?如果还有另一种准确的方法,我的程序可以告诉我什么时候安装完成特定的过程请告诉我怎么样?



Windows 7



谢谢

Hi, I am trying to create an auto shutdown program that will shutdown the computer whenever the user is done downloading or installing things. Right now I'm running into trouble, I tried making the program read for processes that close but the problem is that most downloads and software installations don't automatically exit when they finished so that approach doesn't work. My next move is to try to get my program to read the selected process of the program for idleness, how can I do this? If there is another way that is accurate in which my program can tell when a specific process is done with installation please show me how?

Windows 7

Thanks

推荐答案

没有。当一个进程等待来自控制台的用户输入时,空闲的概念不适用于所有进程,仅适用于其中的一部分。 普通UI线程不使用它,但线程保持等待状态(并使用零CPU),直到用户输入调度到应用程序主窗口,这会唤醒线程。这与闲置不同。此外,你无法知道下一步该做什么。因此,在一般情况下,没有办法判断一个进程是否可以安全终止。这就是为什么,如果您尝试以常规方式关闭系统,它可以请求您确认终止某些进程。这件事非常简单,而且基于这样一个事实:普通的UI进程可以处理来自操作系统的通知,这些通知即将以优雅的方式关闭和终止。某些应用程序可以否决或阻止关闭或只是挂起。没有什么事情发生很快,一些应用程序可以被认为是处理。



有一篇有趣的短篇文章解释微软专利方式关闭操作系统:

http://www.conceivablytech.com/2530/products/ microsoft-patents-operating-system-shutdown [ ^ ]。



-SA
No. The concept if "idle" is not applicable for all processes, only to a part of them, when a process awaits of a user input from a console. "Normal" UI threads do not use it, but the thread is kept in a wait state (and uses zero CPU) until the user input is dispatches to the application main window, which wakes up the thread. This is not the same as idleness. Besides, you cannot know what the process is about to do next. So, in a general case, there is no a way to tell if a process is "safe to terminate". That's why, if you try to shutdown the system in a regular way, it can request you for the confirmation for termination of some processes. This thing is pretty trivial and is based on the fact that normal UI processes can process notifications from the OS which is about to shut down and terminate themselves in a graceful way. Some applications can veto or block shutdown or simply "hang". It nothing happens "soon enough", some application can be considered "handing".

There is an interesting short article explaining Microsoft patented way shutting down the OS:
http://www.conceivablytech.com/2530/products/microsoft-patents-operating-system-shutdown[^].

—SA


这篇关于你怎么知道另一个程序何时闲置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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