Article View: borland.public.cppbuilder.nativeapi
Article #14661Re: Threads and Timer problem
From: Stephan
Date: Wed, 06 Aug 2003 11:40
Date: Wed, 06 Aug 2003 11:40
62 lines
3015 bytes
3015 bytes
Hi Paul,
what does "not make it work" mean?
programming a thread can be tricky,
not from what they tell you to do, but from
what you are not told: you have to think a little differently.
A thread isn't like the code you would write in a class.
When you start a thread, either by calling resume or by instantiating it
in the not paused state, it finds a method called "execute" and runs that
code. When execute completes, that thread is finished.
when execute is running, calling another method from your main program isn't
quite correct. Take a look at the Terminate method. Terminate should be
called
from the main program.
Once your timer expires, how are you getting this information back to the
main program?
Have Fun
Stephan
"Paul E." <paulepst69@aol.com> wrote in message
news:3f30ce2e@newsgroups.borland.com...
thanks all, I used Sleep(5000) inside my thread exeute and it worked, now I
am trying to define the thread in other form of my program so I can control
the start and terminate of my thread, so I declared in the .h file of the
program form
private: // User declarations
TIMConnection * MySampleThread;
and in the CPP file
__fastcall TMainScreen::TMainScreen(TComponent* Owner)
: TForm(Owner)
{
MySampleThread = new TIMConnection;
}
//--------------------------------------------------------------------------
-
void __fastcall TMainScreen::Button1Click(TObject *Sender)
{
MySampleThread->Resume(); // Make the thread start
}
//--------------------------------------------------------------------------
-
void __fastcall TMainScreen::Button2Click(TObject *Sender)
{
MySampleThread->Close(); // Call the Terminate() Method to stop the
thread by calling the Close function inside the thread
}
//--------------------------------------------------------------------------
-
and I can't make it work .....any suggestions what I am doing wrong
Technical Details
Message-ID:
<3f30e92d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!216.166.71.118.MISMATCH!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f2daa27@newsgroups.borland.com> <3f30ce2e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ece7f64e3f770b72 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-06 04:54:04 PST From: "Stephan" <slaska@devarinc.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2daa27@newsgroups.borland.com> <3f30ce2e@newsgroups.borland.com> Subject: Re: Threads and Timer problem Date: Wed, 6 Aug 2003 07:40:28 -0400 Lines: 66 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 64.252.14.74 Message-ID: <3f30e92d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060170029 64.252.14.74 (6 Aug 2003 04:40:29 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!216.166.71.118.MISMATCH!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail