检测进程是否空闲
有没有办法检测Windows进程是否空闲?
空闲 意味着当特定应用程序的进程没有处理任何内容时(应用程序正在等待用户输入)。
干杯
Is there a way to detect whether a Windows process is idle?
idle Means, when a particular application's process is not processing anything(The application is waiting for userinput).
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 SetWindowsHookEx 放置一个钩子WH_FOREGROUND空闲
You can put a hook SetWindowsHookEx with WH_FOREGROUNDIDLE
我在 MFC 案例中发现的有关此主题的简短摘要,在这种情况下,您希望在进程空闲时收到通知(做一些后台工作等),但不是以轮询/等待方式
(变量名称是建议):
-> ;如果它是一个没有模式对话框的 MFC 应用程序:
->如果它是 MFC 应用程序中的对话框:
->如果您想要两者(应用程序和对话框):
.) 将公共成员变量添加到主框架(也可以是静态全局变量)
.) 将方法原型添加到主框架的头文件中,
并包含此内容(请注意,它是不是主框架的成员函数!)
。)在主框架的末尾设置窗口挂钩 ::OnCreate
。)最后,当您完成后,在主框架解构函数中取消挂钩
这些解决方案都不起作用如果应用程序是不活动(另一个应用程序具有焦点)。我在这里看到的唯一解决方案是使用 WM_TIMER 并通过 WaitForInputIdle 检查空闲状态(http://msdn.microsoft.com/en-us/library/ms687022%28VS.85%29.aspx),但这会引入一定的轮询间隔可靠性。
资料来源:
-本页
-http://www.drdobbs.com/184416462
-http://www.codeguru.com/forum/showthread.php?t=199148
-http://www.codeproject.com/KB/对话框/idledialog.aspx?msg=770930
A short summary of what I found about this topic for the MFC case where you want to be notified whenever the process is idle (do some background work etc.) but not in a polling/ waiting fashion
(variable names are suggestions):
-> If its an MFC application without modal dialogs:
-> If its a dialog within a MFC application:
-> If you want both (application & dialogs):
.) add a public member variable to the main frame (also a static global variable is possible)
.) add method prototype to the main frame's header file
with this content (note that it is not a member function of the main frame!)
.) set the window hook at the end of the main frame ::OnCreate
.) At the end when you are finished, unhook the window in the main frame deconstructor
None of these solutions will work if the application is not active (another application has the focus). The only solution I see here is to use a WM_TIMER and to check the idle state by WaitForInputIdle (http://msdn.microsoft.com/en-us/library/ms687022%28VS.85%29.aspx) but this would introduce a certain polling interval dependability.
Sources:
-This page
-http://www.drdobbs.com/184416462
-http://www.codeguru.com/forum/showthread.php?t=199148
-http://www.codeproject.com/KB/dialog/idledialog.aspx?msg=770930
如果您的意思是要检测应用程序是否正常并接收消息(用户输入),请检查此函数的返回:
只需将超时(示例中为 10 毫秒)设置为您认为对您的使用合理的值即可。
If you mean you want to detect if the application is happy and receiving messages (user input) check the return of this function:
Just set the timeout (10ms in the example) to what you think is sensible for your use.