首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

真心请问大牛,

2013-12-02 
真心请教大牛,急急急!!!请问,C++如何判断一个进程或一个程序处于未响应状态或崩溃状态呢?程序未响应[解决

真心请教大牛,急急急!!!
请问,C++如何判断一个进程或一个程序处于未响应状态或崩溃状态呢? 程序未响应
[解决办法]
编译器做不到,只能在写代码的时候尽量避免这些情况的发生
[解决办法]
程序不响应就是程序不处理用户或系统发送的消息了,只要向他发一个消息看能不能达到处理后的效果就知道了。
[解决办法]

引用:
请问,C++如何判断一个进程或一个程序处于未响应状态或崩溃状态呢?


1、不同的平台有不同的实现
2、可以监测线程的状态、数量;可以写一个狗与其保持心跳,没有心跳了即认为死了
等等多种方法
[解决办法]
所谓的未响应,就是你理它它不理你,只要一个程序不理睬外部跟它的联系,就是未响应。
至于崩溃,那就看程序本身的特点了。例如一个执行超复杂运算的程序,如果机器配置很低,那么可能要运算很久,这期间操作系统肯定报这程序未响应,你能说这程序崩溃了吗?
[解决办法]
IsHungAppWindow Function

--------------------------------------------------------------------------------

You call the IsHungAppWindow function to determine if Microsoft Windows considers that a specified application is not responding. An application is considered to be not responding if it is not waiting for input, is not in startup processing, and has not called PeekMessage within the internal timeout period of 5 seconds. 

Syntax

BOOL IsHungAppWindow(          HWND hWnd
);
Parameters

hWnd
[in] Handle to the window. 
Return Value

Returns TRUE if the window stops responding, otherwise returns FALSE. Ghost windows always return TRUE. 


Remarks

The Windows timeout criteria of 5 seconds is subject to change.

Although you can access this function by using LoadLibrary and GetProcAddress combined in Windows versions prior to Windows XP, the function is not accessible using the standard Include file and library linkage. The header files included in Windows XP Service Pack 1 (SP1) and Windows Server 2003 document this function and make it accessible using the appropriate Include file and library linkage. However, this function is not intended for general use. It is recommended that you do not use it in new programs because it might be altered or unavailable in subsequent versions of Windows. 

Function Information

Minimum DLL Version user32.dll 
Header Declared in Winuser.h, include Windows.h 
Import library User32.lib 
Minimum operating systems Windows 2000 

See Also

Windows Overview, IsWindow

--------------------------------------------------------------------------------

热点排行