Tatiana, I can offer this option.
Find the System tab in the component palette. Open it, look for TTimer in the list of components. Add it to the form, in the object inspector we find the Interval property. It is able to take the value of the delay in milliseconds. To set the delay to 5 seconds, you must assign this property a value of 5000 (1 second = 1000 milliseconds).
Then double-click on the TTimer component on the form and write a code handler - that is, your search function of the process.
Then go to the handler button to start the search process.
Double click on the button, we write the following code:
procedure TForm1.aButton1Click(Sender: TObject); var Interval: DWord; StartTime: DWord; StopTime: DWord; begin // Задаем интервал для отсчета 3-х секунд Interval := 3000; // Отсчитываем эти секунды... StartTime := GetTickCount; repeat StopTime := GetTickCount; until (StopTime - StartTime) >= Interval; // Секунды отсчитаны успешно, переходим к первичному поиску процесса if FindTask('Process.exe') = 1 then ShowMessage('Process.exe - запущен!') else ShowMessage('Process.exe - не запущен!'); // Нашли/не нашли, переходим к периодическому поиску процесса, // для чего запускаем предварительно настроенный таймер Timer1.Enabled := true; end;
Help for the GetTickCount function tells us that
This is a trickle-down of the system of the timer, which has been limited to 10 milliseconds to 16 milliseconds.
In other words, the accuracy of the value returned by the function depends on the system timer and ranges from 10 to 16 milliseconds. In this regard, there is no guarantee that the first search process will be performed exactly after 3 seconds. This is what I had in mind when I asked about the permissibility of error.
The same with the TTimer component. For his work, he (the component) creates an invisible window that checks for the presence of a WM_TIMER message in the message queue of this window. Due to the fact that, according to help
The WM_TIMER message is a low-priority message.
Since this message has a low priority , it becomes absolutely impossible to expect an exact response timer in exactly 5 seconds, since the messages with high priority will be processed first, which guarantees a certain delay (minimum, but still).
Thus, the error in the countdown will be present, but it will not affect the solution of your problem.
Information sources:
Gettickcount
WM_TIMER message