Recent

Author Topic: How multithreading occurs in TTimer for animation usage?  (Read 693 times)

avv210

  • New Member
  • *
  • Posts: 13
How multithreading occurs in TTimer for animation usage?
« on: April 19, 2022, 02:55:52 pm »
Hey guys. I use the TTimer component in Lazarus for my animation, the method I use is sleep(). How does multithreading occurs in sleep()? Thank you :D

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: How multithreading occurs in TTimer for animation usage?
« Reply #1 on: April 19, 2022, 05:22:36 pm »
1) TTimer does not use threads. TTimer runs in the main thread.

2) Sleep only affects the thread that calls it.
- Other threads are not affected
- The thread that called "sleep" is blocked during the call. If this is the main thread, then timer events will be delayed until after the sleep.

Dzandaa

  • Sr. Member
  • ****
  • Posts: 250
  • From C# to Lazarus
Re: How multithreading occurs in TTimer for animation usage?
« Reply #2 on: June 29, 2022, 10:34:20 am »
Hi,

There is the code I use for non blocking Sleep:

Code: Pascal  [Select][+][-]
  1. // ************************************
  2. // **** Delay: Non Blocking Sleep *****
  3. // ************************************
  4. procedure Delay(Milis: qword);
  5. var
  6.   TimeSpend: qword;
  7. begin
  8.  
  9.   TimeSpend := GetTickCount64;
  10.   while (GetTickCount64 < TimeSpend + Milis) and (not Application.Terminated) do
  11.     Application.ProcessMessages;
  12.  
  13. end;    
  14.  
Dzandaa

 

TinyPortal © 2005-2018