Article View: borland.public.cppbuilder.nativeapi
Article #14602Re: Threads and Timer problem
From: Paul E.
Date: Mon, 04 Aug 2003 16:14
Date: Mon, 04 Aug 2003 16:14
63 lines
3056 bytes
3056 bytes
stephan,
I really appreciate your help.
Can you please supply me with some code on how to start the timer in the
Execute method, the way you explain it.
Thank your for your help...
"Stephan" <slaska@devarinc.com> wrote in message
news:3f2e4804@newsgroups.borland.com...
> 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:
<3f2e865d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.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> <3f2e4804@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 09:40:37 PST From: "Paul E." <paulepst69@aol.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2daa27@newsgroups.borland.com> <3f2e4804@newsgroups.borland.com> Subject: Re: Threads and Timer problem Date: Mon, 4 Aug 2003 08:14:20 -0800 Lines: 65 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.27.110 Message-ID: <3f2e865d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060013661 62.135.27.110 (4 Aug 2003 09:14:21 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail