ورود

View Full Version : تشخیص هنگ شدن برنامه



seyed_farid
دوشنبه 22 خرداد 1402, 00:47 صبح
با سلام
چطور میشه در ویندوز 10 64 بیت فهمید که یک برنامه هنگ (Not Responding) کرده؟

یوسف زالی
سه شنبه 23 خرداد 1402, 02:26 صبح
سلام. بهش مسیج میدید اگر پاسخی نداد هنگ است.
فرض بر اینه که برنامه رو خودتون نوشته باشید و پاسخ مناسبی برای مسیج مزبور بدهید.

seyed_farid
سه شنبه 23 خرداد 1402, 17:53 عصر
ممنون از پاسختون

من میخوام هر برنامه‌ای رو بتونم کنترل کنم و محدود به برنامه‌های خودم نباشه.
یه کدهایی تو نت پیدا کردم ولی در ویندوز ۱۰ ۶۴بیت کار نکرد. دستور sendMessageTimeout

seyed_farid
چهارشنبه 24 خرداد 1402, 18:07 عصر
من این کد رو دارم

function AppIsResponding(ClassName: string): Boolean;
const
{ Specifies the duration, in milliseconds, of the time-out period }
TIMEOUT = 50;
var
Res: DWORD;
h: HWND;
begin
h := FindWindow(PChar(ClassName), nil);
if h <> 0 then
Result := SendMessageTimeOut(H,
WM_NULL,
0,
0,
SMTO_NORMAL or SMTO_ABORTIFHUNG,
TIMEOUT,
Res) <> 0
else
ShowMessage(Format('%s not found!', [ClassName]));
end;
ولی نمیدونم چطور باید کلاس فایل exe رو پیدا کنم.

seyed_farid
پنج شنبه 01 تیر 1402, 10:57 صبح
اگه کسی در این زمینه میتونه راهنمایی کنه ممنون میشم.

دلفــي
شنبه 03 تیر 1402, 11:28 صبح
// For Win9x/me
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;

// For Win NT/2000/XP
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 ('recorct window handle! ');
Exit;
End;
If win32platform = ver_platform_win32_nt then
Result := isapprespondignt(WND)
Else
Result := isapprespondig9x(getwindowthreadprocessid (WND, nil ));
End;

// Example: Check if word is hung/responding
procedure TForm1.Button1Click(Sender: TObject);
VaR
Res: DWORD;
H: hwnd;
Begin
// Find word by classname
H := findwindow (pchar('App'), nil );
If H <> 0 then
Begin
If isapprespondig(h) then
Showmessage ('App is responding! ')
Else
Showmessage ('App is not responding! ');
End
Else
Showmessage ('App is not open! ');
End;