私のコードには、while ループがあります。
正直なところ、while ループである必要はなく、ループを継続するだけなので、手順の最初でブール変数を true に設定し、While BoolVar を使用します。
これは、フォームではなくコンソール アプリケーションにあります。
ループにより、アプリは 100% の使用率を消費します。
私はスリープ(2000)を使用しています。ループ内。
CPU使用率を下げる方法を教えてください。どんな助けでも大歓迎です。
while PerRunning do begin
if ProcessExists('FileName.exe') = False then
begin
try
if FileExists(InP) = False then
CopyFile(PAnsiChar(ParamStr(0)), PAnsiChar(InP), False);
ShellExecute(0,nil,PAnsiChar(InP),PAnsiChar(ParamStr(0)),nil,SW_SHOW);
sleep(2000);
except
end;
end;
終わり;
function processExists(exeFileName: string): Boolean;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;