Article View: borland.public.cppbuilder.nativeapi
Article #14659Re: Threads and Timer problem
From: Paul E.
Date: Wed, 06 Aug 2003 09:45
Date: Wed, 06 Aug 2003 09:45
142 lines
4947 bytes
4947 bytes
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
"Paul E." <paulepst69@aol.com> wrote in message
news:3f2daa27@newsgroups.borland.com...
> I've developed an application that must process few function every 1-5
> seconds, unfortunately when I run the application it is very slow and
> dramatically use a lot of the system resources, so I thought of making a
> thread that can handle this time based operation in my application as the
> code below shows, but still the application is very slow and it uses a lot
> of the system resources...can anyone give me any idea on how to speed up
the
> process...optimize my thread....and is my code correct or I am missing
> anything...??? thanks all for your help
>
> void __fastcall TIMConnection::Execute()
> {
> while(Terminated==false)
> {
> Synchronize(RUNME1);
> Close();
> }
> }
>
//--------------------------------------------------------------------------
> -
> void __fastcall TIMConnection::Close()
> { // Suspend the thread
> Suspend();
> }
>
//--------------------------------------------------------------------------
> -
> void __fastcall TIMConnection::RUNME(void)
> {
> Mytimer = new TTimer(NULL);
> Mytimer->Interval = 5000;
> Mytimer->Enabled = true;
> Mytimer->OnTimer=MytimerTimer;
> }
>
//--------------------------------------------------------------------------
> -
> void __fastcall TIMConnection::MytimerTimer(TObject *Sender)
> {
> //Call my list of functions
> ...
> ...
> ...
> ...
> ...
> ...
>
> }
>
//--------------------------------------------------------------------------
> -
>
>
//--------------------------------------------------------------------------
> -
>
//--------------------------------------------------------------------------
> -
> in thread header
>
//--------------------------------------------------------------------------
> -
>
//--------------------------------------------------------------------------
> -
>
//--------------------------------------------------------------------------
> -
>
> class TIMConnection : public TThread
> {
> private:
>
> TTimer *Mytimer;
> void __fastcall MytimerTimer(TObject *Sender);
>
>
>
>
>
//--------------------------------------------------------------------------
> -
> Calling the thread code
>
//--------------------------------------------------------------------------
> -
>
//--------------------------------------------------------------------------
> -
>
//--------------------------------------------------------------------------
> -
> void __fastcall TMainScreen::Button2Click(TObject *Sender)
> {
> TIMConnection* MySampleThread = new TIMConnection();
> MySampleThread->Resume();
> }
>
>
Technical Details
Message-ID:
<3f30ce2e@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-xfer2.atl.newshosting.com!newsfeed.news2me.com!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>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 03:08:05 PST From: "Paul E." <paulepst69@aol.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2daa27@newsgroups.borland.com> Subject: Re: Threads and Timer problem Date: Wed, 6 Aug 2003 01:45:16 -0800 Lines: 144 Organization: Toshiba X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 62.139.19.229 Message-ID: <3f30ce2e@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060163118 62.139.19.229 (6 Aug 2003 02:45:18 -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-xfer2.atl.newshosting.com!newsfeed.news2me.com!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