21 January 2011

How to kill a thread in delphi?

How to kill a thread in delphi? TMyThread Execute

procedure TMyThread.Execute;
begin
  while not Terminated do begin
    //Here you do a chunk of your work.
    //It's important to have chunks small enough so that "while not Terminated"
    //gets checked often enough.
  end;
  //Here you finalize everything before thread terminates
end;
With this, you can call
MyThread.Terminate;
There is another method, called 'forced termination'. You can call
TerminateThread(MyThread.ThreadId);

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Blog by Chagridsada Boonthus | http://chagridsada.blogspot.com/