Timer event doesn't get triggered
I have created three timers(5sec,5sec, and 10sec) for my Windows gui. When the timer event is triggered, it displays an Timeout error to a textbox. For some reason, the timers doesn't trigger in some procedures but does in others. I don't believe any process is holding up the code to disallow the timers from triggering. What can I do to debug the problem? Thanks.
DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
Probably you missed some steps in setting up the timer. Give us the steps you carried out upto now. Oh and tell us if it is a MFC or Win32 Application.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
The code is written in VC++ .NET. In my procedures, I call
CmdAckTimer->Start(); // Start timer
CmdAckTimer->Stop(); // Stop timer
static System::Windows::Forms::Timer * CmdAckTimer;
//
// CmdAckTimer
//
this->CmdAckTimer->Interval = 5000; // 5 sec
this->CmdAckTimer->Tick += new System::EventHandler(this, CmdAckTimer_Tick);
void Test::CmdAckTimer_Tick(System::Object * sender, System::EventArgs * e)
{
CmdAckTimer->Stop();
txtStats->Text=String::Concat (S"CmdAckTimer->Stop", S"\r\n",txtStats->Text);
txtStats->Text=String::Concat (S"Error: Cmd Ack Timer timed out ", DateTime::Now.ToLongTimeString(),S"\r\n",txtStats->Text);
}
DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
I dont know much on Windows Forms Applications, but at first glance everything looks okay to me. But where do you call the CmdAckTimer->Start() method? Dont you have to call it here?
//
// CmdAckTimer
//
this->CmdAckTimer->Interval = 5000; // 5 sec
this->CmdAckTimer->Tick += new System::EventHandler(this, CmdAckTimer_Tick);
this->CmdAckTimer->Start();
and inside the TimerEventHandler
void Test::CmdAckTimer_Tick(System::Object * sender, System::EventArgs * e)
{
CmdAckTimer->Stop();
txtStats->Text=String::Concat (S"CmdAckTimer->Stop", S"\r\n",txtStats->Text);
txtStats->Text=String::Concat (S"Error: Cmd Ack Timer timed out ", DateTime::Now.ToLongTimeString(),S"\r\n",txtStats->Text);
CmdAckTimer->Enabled = true;
}
Check it out.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
I make the Start() call in my Button click event. One thing I noticed was that the timer works in an event, but not in a static function.
DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0