I took a working demo source of the waiting timer from microsoft, but it is worth setting the time in it for more than three minutes as it stops working correctly. That is, the timer is triggered instantly and without delay. What could be the reason?
#include <windows.h> #include <stdio.h> int main() { HANDLE hTimer = NULL; LARGE_INTEGER liDueTime; //liDueTime.QuadPart = -100000000LL; // оригинал liDueTime.QuadPart = -(10000000 * 300); // устанавливаем на 5 минут // Create an unnamed waitable timer. hTimer = CreateWaitableTimer(NULL, TRUE, NULL); if (NULL == hTimer) { printf("CreateWaitableTimer failed (%d)\n", GetLastError()); return 1; } printf("Waiting for 10 seconds...\n"); // Set a timer to wait for 10 seconds. if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0)) { printf("SetWaitableTimer failed (%d)\n", GetLastError()); return 2; } // Wait for the timer. if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0) printf("WaitForSingleObject failed (%d)\n", GetLastError()); else printf("Timer was signaled.\n"); return 0; }