1

I have this in a header:

static volatile bool g_operational = true;

then WM_CLOSE has this:

g_operational = false;
WaitForSingleObject(TimerDoneEvent , INFINITE);
DeleteTimerQueueEx(t_main , NULL);

with the timer callback function looking like this:

VOID CALLBACK main_timer(PVOID lpParam , BOOLEAN TimerOrWaitFired) {
    // doing stuff
    if ( !g_operational ) 
        SetEvent(TimerDoneEvent);
}

The timer itself is doing what I expect but the issue is shutting it down from WM_CLOSE, what's happening is g_operational is set to false then the timer thread that's running every second should pick up on g_operational being false then call SetEvent to signal that the thread is done so WaitForSingleObject can continue but within the callback function g_operational always remains true, why is this?

778899
  • 329
  • 3
  • 12
  • why this not visible - no code. but why you use `g_operational` and `TimerDoneEvent` at all ? you need by sense use `DeleteTimerQueueTimer` with `INVALID_HANDLE_VALUE` or `CompletionEvent` instead – RbMm Jan 31 '18 at 17:28
  • 2
    Defining static variables in header files is usually not a good idea. – Jonathan Potter Jan 31 '18 at 17:31
  • 2
    @JonathanPotter - yes, every cpp file will be have private copy of it. as result `main_timer` will be use another `g_operational` variable than `g_operational = false;` but anyway use `g_operational` is error by winapi. need `DeleteTimerQueueTimer` – RbMm Jan 31 '18 at 17:32

0 Answers0