I want to put a delay into a thread for n millisecunds. I can't use the sleep instruction because it stops all my application (all the threads). I've thought using a timer, but is there an equivalent instruction to ProcessMessages in a thread?
Thanks.
Thanks answering. I'm sure I'm in my thread. I create it and put the priority to tpLower. Still my app is stopping when I put sleep in the thread.
Ben.
Procedure TAnimation.StartMoving;
var x, y: Integer;
begin
TheImage.Visible:=True;
If TheStep=0 then TheStep:=1;
For x:=1 To TheStep Do
Begin
TheImage.Visible:=False;
TheImage.Left:=TheLeft1+(x*(TheLeft2-TheLeft1) div x);
TheImage.Top:=TheTop1+(x*(TheTop2-TheTop1) div x);
TheImage.Visible:=True;
Sleep(50);
End;
End;
And Here's where I create the thread in the main code:
i:=Max(abs(TheImage.Left-370) div 30,abs(TheImage.Top-150) div 30);
TheThreadAnimation:=TAnimation.Create(TheImage, i, 370, 150, TheImage.Left, TheImage.Top);
TheThreadAnimation.Priority:= tpLower;
I suppose you want to do a sort of animation, and the image is placed onto the main form right?
one important rule when doing threaded animation : you need synchronization between the main thread and the animation thread, because the drawing takes place in the main thread.
in fact doing a simple animation, a simple TTimer would be enough. if you need a super responsive app and have a complicated animation, you can use a threaded timer like this one :
my bad, that first link was indeed a CBuilder component.
anyway, a quick google search will reveal some components.
my point is : I don't think you need a thread in this case and your problem can be solved with a simple TTimer.
if you want to do FAST animations AND a responsive app, then maybe you'll need threads. remember that most games (even 3D games) are still single threaded...
--------------------------------------
What You See Is What You Get
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.