Dll中使用定时器

请大家仔细看看,我写的这段Dll定时器函数代码,它的效率如何:

DWORD WINAPI TimerThread(LPVOID pamaram) { UINT oldTickCount, newTickCount; oldTickCount = GetTickCount(); while(TRUE) { while(TRUE) { newTickCount = GetTickCount(); if(newTickCount - oldTickCount >= 60000) { oldTickCount = newTickCount; break; } } // 60毫秒自动调用函数 SomeFun(); } return 0; }

 

再看看侦探大佬帮我修正后的代码:

(SwitchToThread主要是用来腾出时间片让其他线程执行,这样可以提高在单核机器的CPU的执行效率)

DWORD WINAPI TimerThread(LPVOID pamaram) { UINT oldTickCount, newTickCount; oldTickCount = GetTickCount(); while(TRUE) { while(TRUE) { newTickCount = GetTickCount(); if(newTickCount - oldTickCount >= 60000) { oldTickCount = newTickCount; break; } else SwitchToThread(); } // 60毫秒自动调用函数 SomeFun(); } return 0; }

你可能感兴趣的:(dll,winapi)