BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reexecutinh TThread

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Adam
Guest





PostPosted: Mon Mar 07, 2005 6:16 pm    Post subject: reexecutinh TThread Reply with quote



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





PostPosted: Mon Mar 07, 2005 9:29 pm    Post subject: Re: reexecutinh TThread Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.