Home > Software engineering >  Why to wait for the timer twice before triggering time interval is wrong?
Why to wait for the timer twice before triggering time interval is wrong?

Time:09-21

In the main thread call
HANDLE hTimer=CreateWaitableTimer (NULL, FALSE, NULL);
LARGE_INTEGER li;
Li. QuadPart=0;
SetWaitableTimer (hTimer, & amp; Li, 100, NULL, NULL, FALSE);

The thread function
DWORD WINAPI SendDataThread (PVOID pvParam)
{
While (TRUE)
{
DWORD dw=WaitForSingleObjectEx (hTimer, INFINITE, TRUE);

If (dw==WAIT_IO_COMPLETION)
{
return 0;
}
Else if (dw==WAIT_OBJECT_0)
{//serial port to send
Cstrings STR=_T (" 123456789 ");
M_MSComm. Put_Output (COleVariant (STR));
}
}
}

Results pictures
Why isn't the time interval of two times before 100 milliseconds, always don't understand

CodePudding user response:

Don't sink...

CodePudding user response:

Guess the main thread of start the timer to the thread execution of more than 100 ms
Can try put SetWaitableTimer thread while before


CodePudding user response:

Else if (dw== WAIT_OBJECT_0
Have been waiting to

CodePudding user response:

Turn 100 ms try (such as 500 ms)

CodePudding user response:

15 ms Windows timing accuracy of material

CodePudding user response:

Multimedia timer
  • Related