调用 SetTimer 启动新定时器后,我可以在该定时器的 TimerProc 中调用 KillTimer 吗?

问题描述 投票:0回答:0

例如,假设我有以下

TimerProc

#include <Windows.h>
#define IDT_TIMER1 1001
BOOL g_fKillTimer = FALSE;

VOID DoTimerTask(); // Among other things, sets the flag `g_fKillTimer` when needed

// Timer is started elsewhere with a call to: 
//  SetTimer(hWnd, IDT_TIMER1, 10000, TimerProc);
VOID CALLBACK TimerProc(
    _In_ HWND hWnd,
    _In_ UINT uMsg,
    _In_ UINT_PTR idEvent,
    _In_ DWORD dwTime
)
{
    if (TRUE == g_fKillTimer)
    {
        KillTimer(hWnd, IDT_TIMER1);
    }
    DoTimerTask();
}

此代码是否会成功终止计时器

IDT_TIMER1
?还是我在定时器程序本身内调用
KillTimer
的事实可能会为此带来问题?函数
DoTimerTask()
还会被调用吗?

c winapi timer
© www.soinside.com 2019 - 2024. All rights reserved.