Board index » delphi » how to terminate a thread from main thread of a application

how to terminate a thread from main thread of a application

I have a multithread application, click a button, a special thread begin to
perform, now, I want to terminate the thread from main applicatin when it is
running. how to do it ?

some source or samples will be fine!

thanks for all!

David Y

twoy2...@sina.com

 

Re:how to terminate a thread from main thread of a application


if you are using the tthread class you can simply create the thread object
public, and when you want to kill it use the terminate method.
You could also grab the thread handle and kill it with the api function
terminateprocess.

Quote
"David Y" <twoy2...@sina.com> wrote in message news:3af251d9_2@dnews...
> I have a multithread application, click a button, a special thread begin
to
> perform, now, I want to terminate the thread from main applicatin when it
is
> running. how to do it ?

> some source or samples will be fine!

> thanks for all!

> David Y

> twoy2...@sina.com

Re:how to terminate a thread from main thread of a application


thanks
Quote
"Tony Caduto" <tcad...@execpc.com> wrote in message news:3af2bd6a_1@dnews...
> if you are using the tthread class you can simply create the thread object
> public, and when you want to kill it use the terminate method.
> You could also grab the thread handle and kill it with the api function
> terminateprocess.

> "David Y" <twoy2...@sina.com> wrote in message news:3af251d9_2@dnews...
> > I have a multithread application, click a button, a special thread begin
> to
> > perform, now, I want to terminate the thread from main applicatin when
it
> is
> > running. how to do it ?

> > some source or samples will be fine!

> > thanks for all!

> > David Y

> > twoy2...@sina.com

Re:how to terminate a thread from main thread of a application


I use API ExitThread, but the main process is also killed.
Quote
"Tony Caduto" <tcad...@execpc.com> wrote in message news:3af2bd6a_1@dnews...
> if you are using the tthread class you can simply create the thread object
> public, and when you want to kill it use the terminate method.
> You could also grab the thread handle and kill it with the api function
> terminateprocess.

> "David Y" <twoy2...@sina.com> wrote in message news:3af251d9_2@dnews...
> > I have a multithread application, click a button, a special thread begin
> to
> > perform, now, I want to terminate the thread from main applicatin when
it
> is
> > running. how to do it ?

> > some source or samples will be fine!

> > thanks for all!

> > David Y

> > twoy2...@sina.com

Re:how to terminate a thread from main thread of a application


procedure MyThread.Execute;
begin
  while not Terminated do
  begin
    // loop code
  end;
end;

procedure MyForm.DoCreateThread;
begin
  MyThread := TMyThread.Create(false);
end;

procedure MyForm.DoSomething;
begin
  MyThread.FreeOnTerminate := true; // thread will free itself
  MyThread.Terminate;
end;

Other Threads