Article View: borland.public.cppbuilder.nativeapi
Article #13780Re: TThread
From: Remy Lebeau (TeamB)
Date: Fri, 12 Sep 2003 18:19
Date: Fri, 12 Sep 2003 18:19
85 lines
3157 bytes
3157 bytes
"Andy" <andyholcomb@comcast.net> wrote in message
news:3f61ffd2$2@newsgroups.borland.com...
> Would I be correct in assuming that most of the time
> I will not need ti use Synchronize?
That depens on what your thread is actually doing. There are times when
Synchronize() is warranted.
However, given your previous example, I would suggest re-writing the code
like this instead:
TthreadTest *TestItThread = NULL;
//Start Thread Button
void __fastcall TForm1::Button1Click(TObject *Sender)
{
StopTest();
TestItThread = new TthreadTest(Handle); // create and run the thread
}
///Stop Button
void __fastcall TForm1::StopCodeClick(TObject *Sender)
{
StopTest();
}
void __fastcall TForm1::::StopTest()
{
if( TestItThread )
{
TestItThread->Terminate();
TestItThread->WaitFor();
delete TestItThread;
TestItThread = NULL;
}
}
///////////////Thread Code
class TthreadTest : public TThread
{
private:
HWND FWnd;
protected:
void __fastcall Execute();
void __fastcall AfterConstruction();
public:
__fastcall TthreadTest::TthreadTest(HWND hWnd);
}
__fastcall TthreadTest::TthreadTest(HWND hWnd)
: TThread(true), FWnd(hWnd)
{
}
void __fastcall TthreadTest::AfterConstruction()
{
Resume();
}
void __fastcall TthreadTest::Execute()
{
HDC DC = GetDC(FWnd);
for(int i = 0; ((i <= 300000) && (!Terminated)); ++i)
{
String S = i;
TextOut(DC, 10, 10, S.c_str(), S.Length());
}
ReleaseDC(FWnd, DC);
}
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
Technical Details
Message-ID:
<3f620dfe$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f60e4dc$1@newsgroups.borland.com> <3f6114aa$1@newsgroups.borland.com> <3f61eebb$1@newsgroups.borland.com> <3f61f99e$3@newsgroups.borland.com> <3f61fc43$1@newsgroups.borland.com> <3f61fdf5$1@newsgroups.borland.com> <3f61ffd2$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,b3bd84980f619f6 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-09-12 11:26:31 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f60e4dc$1@newsgroups.borland.com> <3f6114aa$1@newsgroups.borland.com> <3f61eebb$1@newsgroups.borland.com> <3f61f99e$3@newsgroups.borland.com> <3f61fc43$1@newsgroups.borland.com> <3f61fdf5$1@newsgroups.borland.com> <3f61ffd2$2@newsgroups.borland.com> Subject: Re: TThread Date: Fri, 12 Sep 2003 11:19:21 -0700 Lines: 87 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: 207.175.226.26 Message-ID: <3f620dfe$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1063390718 207.175.226.26 (12 Sep 2003 11:18:38 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail