SleepEx suspends the current thread until the specified condition is
met. I expected the execution to resume when occurs the timeout happens
in my following example.
At the expiry of the timer it is calling "lpFnToCompletionRoutine" as
expected, but it is not printing Count in the while loop. Can anyone
explain why?
static void APIENTRY lpFnToCompletionRoutine (LPVOID lpCount,
DWORD dwTimerLowValue,
DWORD dwTimerHighValue)
{
*(LPWORD) lpCount = *(LPWORD) lpCount + 1;
}
void OmciAdapter::adapterMain()
{
/* STEPS to DO: */
//1. set the timer for every 100 milli secs to check for any OMCI
timeouts
HANDLE hTimer;
LARGE_INTEGER DueTime;
DWORD Count = 0;
const int unitsPerSecond=10*1000*1000; // 100 nano seconds
DueTime.QuadPart = -(10000 * 10000);
hTimer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
if (NULL == hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return;
}
printf("Waiting for 10 seconds...\n");
// Set a timer to wait for 10 seconds.
if (!SetWaitableTimer(hTimer, &DueTime, 10000,
lpFnToCompletionRoutine, &Count, FALSE))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return;
}
while (1)
{
printf ("Count = %d \n", Count);
SleepEx(INFINITE, TRUE);
}
.................
.................
.................
.................
}