Article View: borland.public.cppbuilder.nativeapi
Article #13769Re: TThread
From: Andy
Date: Fri, 12 Sep 2003 16:14
Date: Fri, 12 Sep 2003 16:14
57 lines
2158 bytes
2158 bytes
>I suspect that a more likely scenario could be that your thread isn't
>releasing it's timeslice at all and is taking up all the processor time.
>Try adding in some ::Sleep(n) instructions (particular within loops), where
>n is a number of milliseconds - I typically use 0, 50, 100, 250, 500, or
>1000, depending on what the thread is designed to do.
But how come if I do it this way it works?
Andy
///Start Thread Button
void __fastcall TForm1::bUseThreadClick(TObject *Sender)
{
StopNow = false;
DWORD ThreadID;
HANDLE hthread = CreateThread(
0,
0,
ThreadFunc,
0,
0,
&ThreadID);
if (hthread == 0)
MessageBox(Handle, "No Thread", 0, MB_OK);
}
/////Thread Function
DWORD CALLBACK ThreadFunc(void* P)
{
Form1->Countloop();
return 0;
}
//// Same Loop operation as the one I sent Gambit
void __fastcall TForm1::Countloop()
{
HDC DC = GetDC(Form1->Handle);
for (int i = 0; ((i<=300000) && (!Form1->StopNow));i++ ) {
//Label1->Caption = IntToStr(i);
String S = i;
TextOut(DC, 10, 10, S.c_str(), S.Length());
}
ReleaseDC(Form1->Handle, DC);
//return 0;
}
//// Stop Button
void __fastcall TForm1::StopCodeClick(TObject *Sender)
{
StopNow = true;
}
Technical Details
Message-ID:
<3f61f0f2$1@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!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f60e4dc$1@newsgroups.borland.com> <3f611222$1@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 09:20:02 PST From: "Andy" <andyholcomb@comcast.net> Sender: "Andy" <andyholcomb@comcast.net> Reply-To: "Andy" <andyholcomb@comcast.net> Subject: Re: TThread Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 66.12.8.230 66.12.8.230 References: <3f60e4dc$1@newsgroups.borland.com> <3f611222$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3f61f0f2$1@newsgroups.borland.com> Date: 12 Sep 2003 09:14:42 -0700 X-Trace: newsgroups.borland.com 1063383282 207.105.83.65 (12 Sep 2003 09:14:42 -0700) Lines: 57 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail