Article View: borland.public.cppbuilder.nativeapi
Article #14738Re: Threads and Timer problem
From: Malcolm Smith
Date: Mon, 04 Aug 2003 11:24
Date: Mon, 04 Aug 2003 11:24
113 lines
4188 bytes
4188 bytes
I'm not sure why you are triggering a TTimer this way. If you are after a
thread that processes a task after a given period of time check out my
tutorials page. I have just the class for you. Look for TWaitEventThread.
--
Malcolm Smith
MJ Freelancing- http://www.mjfreelancing.com
Software Protection for C++Builder
Borland Technology Partner
"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:
<3f2e415c$1@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!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!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-04 04:40:08 PST Reply-To: "Malcolm Smith" <mjfreelancing@optusnet.com.au> From: "Malcolm Smith" <mjfreelancing@optusnet.com.au> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2daa27@newsgroups.borland.com> Subject: Re: Threads and Timer problem Date: Mon, 4 Aug 2003 21:24:17 +1000 Lines: 115 Organization: MJ Freelancing 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: 211.28.166.113 Message-ID: <3f2e415c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059995996 211.28.166.113 (4 Aug 2003 04:19:56 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail