Article View: borland.public.cppbuilder.nativeapi
Article #14739Re: Threads and Timer problem
From: Stephan
Date: Mon, 04 Aug 2003 11:48
Date: Mon, 04 Aug 2003 11:48
48 lines
2639 bytes
2639 bytes
Hi
you have an interesting thing going on here, but I don't think it's
doing what you want. As you know, when you create a thread,
it runs independently of the process that creates it. It still takes time
and resources to execute. The good thing about it is it will allow
the main program to react to user input, redraw the screen, etc
while the thread is busy doing some processor intensive task.
The major task to deal with in a thread is to get the results of the
thread task back to main program. there are several ways of doing
this, including the synchronize method, and mutexs
The synchronize method takes a bit of code written for the thread
and causes it to execute in the main thread (program).
The synchronized code can only execute in the main thread when the
main thread is not executing any other code
The code you wrote starts a timer in the main thread
perhaps what you meant to do was to have the timer run in the thread?
in that case, start the timer in the Execute method, then the timer event
should call a routine that Synchronizes the code that you want to execute
in the main thread.
Have Fun
Stephan
"Paul E." <paulepst69@aol.com> wrote in message
news:3f2daa27@newsgroups.borland.com...
application must process few function every 1-5 seconds,
void __fastcall TIMConnection::Execute()
{
while(Terminated==false)
{
Synchronize(RUNME);
Close();
}
}
void __fastcall TIMConnection::RUNME(void)
{
Mytimer = new TTimer(NULL);
Mytimer->Interval = 5000;
Mytimer->Enabled = true;
Mytimer->OnTimer=MytimerTimer;
}
Technical Details
Message-ID:
<3f2e4804@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!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 05:10:02 PST From: "Stephan" <slaska@devarinc.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2daa27@newsgroups.borland.com> Subject: Re: Threads and Timer problem Date: Mon, 4 Aug 2003 07:48:20 -0400 Lines: 51 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: <3f2e4804@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059997700 64.252.14.74 (4 Aug 2003 04:48:20 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail