How To Detect If an Application Has Stopped Responding
来源:互联网 发布:软件开发工作室黄页 编辑:程序博客网 时间:2024/06/05 13:13
简介:本文描述了使用C++、VB、Windows API和.Net类库如何判断一个进程是否停止了响应。
没有一个明确的“停止响应”的定义,例如对于Internet Explorer或者Word 2000这样的多顶层窗口应用程序,可能存在部分顶层窗口失去响应的情况,这时很难定义应用程序是否停止了响应。但是一般来说,很多应用程序只有一个标志性窗口(或者叫主窗口)。如果主窗口在一段时间内不响应用户操作的时候,对于用户来说应用程序是停止响应的(例如在Internet Explorer等待远程FTP服务器返回登录结果时)。尽管这经常属于其他应用程序应该妥善考虑的范畴,但是如果自己的应用程序依赖于这样的程序而没有源代码级控制权,那么应该提供一个机会允许用户中断对外部应用程序的等待或者干脆终止外部应用程序。
Windows2000及Windows XP中提供了一个API IsHungAppWindow,但是微软声明此函数可能在后续的Windows版本中删除这个函数。不用遗憾,在Windows 32中有一个特殊的消息WM_NULL,在其文档中说明它可以和SendMessageTimeout一起用于判断某个窗口是否停止了响应。一般来说,我们需要获得进程的标志性窗口(或者叫主窗口)来执行这个判断。2002年7月的MSDN杂志Q&A专栏文章Get the Main Window, Get EXE Name 说明了如何做到这一点。很遗憾,附录中的文章How To Detect If an Application Has Stopped Responding中通过访问浏览器对象的hwnd属性绕过了这个过程,或许是因为在VB中调用EnumWindow比较繁琐;参见附录中的Enumerating Windows Using API(VB)。
另外,.Net Framework中提供了一个Responding属性,可以用于检测进程是否停止了响应。附录中的两篇基于.Net的文章就是检查了这个属性。看起来这似乎是通过检查进程的MainWindowHandle指明的窗口是否立刻响应来解决的。通过这种方法判断的缺点是无法设置等待超时的时间。
参考资料
IsHungAppWindow(MSDN)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/ishungappwindow.asp
WM_NULL(MSDN)
(http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_null.asp
Process.Responding Property (MSDN)
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassRespondingTopic.asp
如何“干净地”终止 Win32 中的应用程序
http://support.microsoft.com/kb/178893/zh-cn
How To Detect If an Application Has Stopped Responding
http://support.microsoft.com/kb/231844
304991 Detect if an Application Has Stopped Responding by Using C#
http://support.microsoft.com/kb/304991
304990 Detect if an Application has Stopped Responding by Using Visual Basic .NET
http://support.microsoft.com/kb/304990
Get the Main Window, Get EXE Name
http://msdn.microsoft.com/msdnmag/issues/02/07/CQA/
Enumerating Windows Using API(VB)
http://www.vbaccelerator.com/home/VB/Code/Libraries/Windows/Enumerating_Windows/article.asp
- How To Detect If an Application Has Stopped Responding
- How To Detect If an Application Has Stopped Responding
- How To Detect If an Application Has Stopped Responding
- How To Detect If an Application Has Stopped Responding
- Registering an Application to a URL Protocol
- How to Create an Application that has Office Style
- how to determine if an iOS device has a cellular radio
- how to determine if an iOS device has a cellular radio
- How to kill a not responding application on Linux
- The application ... has stopped unexpectedly
- The application has stopped unexpectedly
- How to obfuscate an Android application
- How to implement an UEFI Shell Application
- how to know whether an element has an class
- How to start next activity if the top activity is stopped/killed
- Detect Input Method Changes
- How to Add Core Data to an existing Utility Application
- unable to detect application namespace
- 编程控制Modem/PPPoE拨号连接
- 编程实现远程唤醒PC
- 限制应用程序的实例数目
- [zz]sysfader:iexplore.exe-应用程序错误的解决方法
- 编程控制活动桌面,用ActiveX控件来增强桌面的功能
- How To Detect If an Application Has Stopped Responding
- 思比科系列CMOS图像传感器应用方案分析
- 捕捉屏幕的时候包含鼠标
- 在richedit控件中插入动态GIF
- 麻省理工学院 电机工程与资讯科学(Electrical Engineering and Computer Science) 在线课程列表
- 浏览器集成教学 自定义浏览器(Updated for Windows XP SP2)
- 毕业后的期望
- 转换指南: 将程序从托管C++扩展迁移到C++/CLI
- DLL/OCX中的MFC对话框不能处理Tab和回车键的问题