VC++中不占CPU的延时方法:
int CtestThreadDlg::DelayTime(int m)//参数为延时秒数 { HANDLE hTimer = NULL; HANDLE hT[2]; LARGE_INTEGER liDueTime; liDueTime.QuadPart = m *(-100000000) / 10; hTimer = CreateWaitableTimer(NULL, TRUE, _T("theTimer")); hT[0] = hTimer; if (!hTimer) { return 1; } if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, FALSE)) { CloseHandle(hTimer); return 2; } DWORD lBusy; do { lBusy = MsgWaitForMultipleObjects(1, hT, FALSE, 0xffff, QS_ALLINPUT); const MSG msg; GetMessage((LPMSG) &msg, NULL, 0, 0); DispatchMessage(&msg); } while (lBusy == (WAIT_OBJECT_0 + 1)); CloseHandle(hTimer); return 0; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。