The safest way to idle a delphi application to wait for a timer?

I am making a delphi application that will run on my computer 24/7 in the background and checks if it needs to do something or not, wait 30 minutes and check again, etc.

How can I make sure that the application will not overload the processor or memory due to the fact that it works all the time.

+3
source share
7 answers

Most programming languages ​​have a “sleep” function that you can call to make the program stop doing things.

; , ...

, . , , , Windows Scripting Host , .

0

timer 30 / . , .

, .

+14

- , : , . .. , , . , , , , 8 , - , 16 ( , ..).

, :

OnMyTimer...
begin
  MyTimer.Enabled := false;
  try
    DoSomethingForALongTime;  // Usually runs in 45 seconds, but sometimes takes 45 minutes!
  finally
    MyTimer.Enabled := true;  // and (SomeAbortRequest = False) and (SomeHorribleErrorCount = 0);  
  end;
end;
+5

- , . , , . , " " , 1% .

, . VCL , , , , .

+1

, , "sleep". , . (, Windows , .)

( ), . , . , , ( , ..)

, , , .

, , / . , "" "", .

0

, , CPU, (, ).

, / " " .

, , Sleep() , , .

YieldThread()/SwitchToThread() (, Now()), , , ... !

WaitForMultipleObjects , .

0

I would suggest creating a service application (set the startup type as automatic) and use CreateTimerQueueTimer as a timer. Memory leaks can be mitigated by reserving memory requirements / pool classes.

0
source

Source: https://habr.com/ru/post/1745337/


All Articles