這兩個代碼有什麼區別? 什麼是最好的/最快的方式。 試圖讓我自己的WM_TIMER線程。std :: this_thread :: get_id()與傳遞ID
第一:timerThreadProc
與get_id()
DWORD WINAPI timerThreadProc(DWORD dwMilliseconds)
{
while (!bExit)
{
if (std::this_thread::get_id() == hTimer1Thread.get_id())
{
// do what ever
Beep(10000, 100);
}
if (std::this_thread::get_id() == hTimer2Thread.get_id())
{
// do what ever
Beep(1000, 100);
}
Sleep(dwMilliseconds);
}
return 1;
}
第二:timerThreadProc
而不get_id()
#define TIMER1 1
#define TIMER2 2
DWORD WINAPI timerThreadProc(UINT ID, DWORD dwMilliseconds)
{
while (!bExit)
{
if (ID == TIMER1)
{
// do what ever
Beep(10000, 100);
}
if (ID == TIMER2)
{
// do what ever
Beep(1000, 100);
}
Sleep(dwMilliseconds);
}
return 1;
}