How to avoid GUI freeze when calling Beginthread API?
Posted
by isa
on Stack Overflow
See other posts from Stack Overflow
or by isa
Published on 2010-03-24T14:02:19Z
Indexed on
2010/03/24
14:03 UTC
Read the original article
Hit count: 209
delphi
Below just a simple race between 2 button in 2 threads,
and this will freeze other components on the form.
procedure moveButton1();
var
I: Integer;
begin
for I := 0 to 6000 do
Form1.Button1.Left := Form1.Button1.Left - 1;
Form1.Caption := 'Button1 won!';
EndThread(0);
end;
procedure moveButton2();
var
I: Integer;
begin
for I := 0 to 6000 do
Form1.Button2.Left := Form1.Button2.Left - 1;
Form1.Caption := 'Button2 won!';
EndThread(0);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
thread1, thread2,tick : Integer;
id1, id2 : LongWord;
begin
thread1 := BeginThread(nil,
0,
Addr(moveButton1),
nil,
0,
id1);
thread2 := BeginThread(nil,
0,
Addr(moveButton2),
nil,
0,
id2);
CloseHandle(thread1);
CloseHandle(thread2);
end;
© Stack Overflow or respective owner