开发者

Timer working in Console Application

开发者 https://www.devze.com 2023-04-07 23:18 出处:网络
I\'m trying to get a timer working in my c++ application. I can define my timer: #defineIDT_TIMERWM_USER + 200

I'm trying to get a timer working in my c++ application.

I can define my timer:

#define  IDT_TIMER  WM_USER + 200 
UINT Timeval;
UINT TimerID开发者_JS百科 = 1;
UINT TimerMS = 20; 

Start Stop Timer methods:

UINT NAHDPbx::StartTimer (UINT TimerID)
    {

      UINT    TimerVal;
      TimerVal =  thewindow->SetTimer(TimerID, TimerMS, NULL);  // Starting the Timer
      return TimerVal;

    }// end StartTimer

BOOL NAHDPbx::StopTimer (UINT TimerID)
   {
          if (!KillTimer (TimerID))
          {
           return FALSE;
          }

         return TRUE;

   } // end StopTimer

And I start the timer like this:

Timeval=StartTimer(TimerID);

However in my code the timer tick never fires:

void NAHDPbx::OnTimer(UINT nIDEvent)
{
    StopTimer(TimerID);

        //Do stuff

    StartTimer(TimerID);
}

Any examples of getting a timer to work? My end goal is to receive data via UDP, and need a way to send and receive at the same time.


If the console application exits, the timer handler will go out of scope and nothing will happen.

0

精彩评论

暂无评论...
验证码 换一张
取 消