 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Adam Guest
|
Posted: Mon Mar 07, 2005 6:16 pm Post subject: reexecutinh TThread |
|
|
Hello!
How can I execute thread (derived from TThread) ? Execute() method has
already finished, and I would like to execute this thread once again without
destroing and creating object. Resume() doesn't work, and Execute method
cannot be called directly.
thanks
Adam
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Mar 07, 2005 9:29 pm Post subject: Re: reexecutinh TThread |
|
|
"Adam" <wadi (AT) poczta (DOT) onet.pl> wrote
| Quote: | How can I execute thread (derived from TThread) ?
|
You don't execute it yourself. It is called automatically when the
underlying thread object begins running.
| Quote: | Execute() method has already finished, and I would like to execute
this thread once again without destroing and creating object.
|
There is no way to do that. Once Execute() exists, the underlying thread is
finished as no longer running and cannot be restarted.
The only way to do what you are asking for is to not let Execute() finish to
begin with. Change your Execute() code to run inside a loop. At the end of
an iteration of the loop, if the thread has not been signalled for
termination then suspend the thread, keeping it running. When you need the
thread later, resume the thread and let the loop continue, re-executing the
thread's work. In other words:
void __fastcall TMyThread::Execute()
{
while( !Terminated )
{
// do work...
if( !Terminated )
Suspend();
}
}
TMyThread *thread = new TMyThread(false);
//...
if( thread->Suspended )
thread->Resume();
// ...
thread->Terminate();
thread->Resume();
//...
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|