mike_k
2008-09-29 19:04:11 UTC
My main app creates a TThread object that in turn creates a TTimer in
its (the thread's) constructor. The Execute method in the thread is
just a message handler:
clsDChannel::clsDChannel(char *caller, char *ConfigData, int *status,
bool CreateSuspended)
: TThread(CreateSuspended)
{
ChannelTimer = new TTimer(0);
ChannelTimer->OnTimer=ChanTime;
ChannelTimer->Enabled=false;
}
void clsDChannel::Execute()
{
// create TCP socket
Dsocket = new clsDSocket(ConfigData);
ChannelTimer->Enabled = true; // this timer created in
clsDChannel constructor
while (!Terminated)
Application->ProcessMessages();
}
void __fastcall clsDChannel::ChanTime(TObject *Sender)
{
Application->ProcessMessages();
}
If I breakpoint ChanTime(), it's in the main application thread. When
I breakpoint the 'while(!Terminated)' message handler loop, it's in
the child thread, as expected.
I'm having problems with this thread eating the CPU, and I don't know
if this is related or not. How would I ensure this thread class has
its own independent timer?
its (the thread's) constructor. The Execute method in the thread is
just a message handler:
clsDChannel::clsDChannel(char *caller, char *ConfigData, int *status,
bool CreateSuspended)
: TThread(CreateSuspended)
{
ChannelTimer = new TTimer(0);
ChannelTimer->OnTimer=ChanTime;
ChannelTimer->Enabled=false;
}
void clsDChannel::Execute()
{
// create TCP socket
Dsocket = new clsDSocket(ConfigData);
ChannelTimer->Enabled = true; // this timer created in
clsDChannel constructor
while (!Terminated)
Application->ProcessMessages();
}
void __fastcall clsDChannel::ChanTime(TObject *Sender)
{
Application->ProcessMessages();
}
If I breakpoint ChanTime(), it's in the main application thread. When
I breakpoint the 'while(!Terminated)' message handler loop, it's in
the child thread, as expected.
I'm having problems with this thread eating the CPU, and I don't know
if this is related or not. How would I ensure this thread class has
its own independent timer?