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.

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.

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);
 }

Edited 3 Years Ago by pyTony: fixed formatting

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.

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.

This article has been dead for over six months. Start a new discussion instead.