Article View: borland.public.cppbuilder.nativeapi
Article #14714Threads and Timer problem
From: Paul E.
Date: Mon, 04 Aug 2003 00:34
Date: Mon, 04 Aug 2003 00:34
84 lines
3458 bytes
3458 bytes
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:
<3f2daa27@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ece7f64e3f770b72,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-03 17:37:36 PST From: "Paul E." <paulepst69@aol.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Threads and Timer problem Date: Sun, 3 Aug 2003 16:34:45 -0800 Lines: 86 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.135.7.228 Message-ID: <3f2daa27@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059957287 62.135.7.228 (3 Aug 2003 17:34:47 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!border3.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