title: Delphi : Sleep without freeze and processmessages
body: <p>I need a way to pause the execution of a function for some seconds. I know i can use the sleep method to do it, but this method 'freezes' the application while its execution. I also know i can use something like the code below to avoid freezing :</p>
  
  <pre><code>// sleeps for 5 seconds without freezing 
  for i := 1 to 5 do
      begin
      sleep(1000);
      application.processmessages;
      end;
  </code></pre>
  
  <p>There are two problems of this approach : one is the fact the freezing still occurs each one second and the second problem is the calling to 'application.processmessages' each second. My app is CPU intensive and each processmessages call do a lot of unnecessary work that uses unnecessary CPU power ; i just want to pause the workflow, nothing more.</p>
  
  <p>What i really need would be a way to pause the execution just like a TTimer, in the example below :</p>
  
  <pre><code>   // sleeps for 5 seconds
     mytimer.interval := 5000;
     mytimer.enabled := true;
     // wait the timer executes
     // then continue the flow
     // running myfunction
     myfunction;
  </code></pre>
  
  <p>The problem of this approach is 'myfunction' won't wait the for mytimer, it will run right after the mytimer is enabled.</p>
  
  <p>Is there another approach to achieve a pause like i want ?</p>
  
  <p>Thanks in advance.</p>