如何判断某个程序是否卡住

gyj5240 2010-07-20 11:36:04
我想问下我有没有什么办法用一个程序去判断 另一个程序运行是否卡住了?
就是半天没反应,有可能一会又反应过来了

我是模拟操作用的,有时候那个程序会出现卡住半天,有可能就死了,有可能又活过来了?如何去判断?
...全文
177 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bt_zhj 2010-07-20
  • 打赏
  • 举报
回复
socket
sanguomi 2010-07-20
  • 打赏
  • 举报
回复
注入一个DLL,定时和你的程序通讯
zhaodog 2010-07-20
  • 打赏
  • 举报
回复
进程通信方法很多呀
发消息
管道
socket
共享内存
等等
gyk120 2010-07-20
  • 打赏
  • 举报
回复
SendMessageTimeout
还有一种办法。
function IsAppRespondig9X(dwThreadId: DWORD): Boolean;
type
TIsHungThread = function(dwThreadId: DWORD): BOOL; stdcall;
var
hUser32: THandle;
IsHungThread: TIsHungThread;
begin
Result := True;
hUser32 := GetModuleHandle('user32.dll');
if (hUser32 > 0) then
begin
@IsHungThread := GetProcAddress(hUser32, 'IsHungThread');
if Assigned(IsHungThread) then
begin
Result := not IsHungThread(dwThreadId);
end;
end;
end;

function IsAppRespondigNT(wnd: HWND): Boolean;
type
TIsHungAppWindow = function(wnd:hWnd): BOOL; stdcall;
var
hUser32: THandle;
IsHungAppWindow: TIsHungAppWindow;
begin
Result := True;
hUser32 := GetModuleHandle('user32.dll');
if (hUser32 > 0) then
begin
@IsHungAppWindow := GetProcAddress(hUser32, 'IsHungAppWindow');
if Assigned(IsHungAppWindow) then
begin
Result := not IsHungAppWindow(wnd);
end;
end;
end;

function IsAppRespondig(Wnd: HWND): Boolean;
begin
if not IsWindow(Wnd) then
begin
ShowMessage('Incorrect window handle!');
Exit;
end;
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := IsAppRespondigNT(wnd)
else
Result := IsAppRespondig9X(GetWindowThreadProcessId(Wnd,nil));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Res: DWORD;
h: HWND;
begin
h := FindWindow(nil, 'notepad');
if h > 0 then
begin
if IsAppRespondig(h) then
ShowMessage('notepad 有响应')
else
ShowMessage('notepad 无响应');
end
else
ShowMessage('未打开 notepad');
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧