首页 > 代码库 > 可等待计时器添加APC测试
可等待计时器添加APC测试
unsigned APIENTRY ThreadProc(void *p)
{
WaitForSingleObject(g_hWaitableTimer, INFINITE);
MessageBox(NULL, _T("线程开始启动"), _T("HELLO"), MB_OK);
return 0;
}
void APIENTRY ApcCompletionRoutine(PVOID pParm, DWORD dwTimerLowValue, DWORD dwTimeHighValue)
{
MessageBox(NULL, _T("ApcCompletionRoutine开始启动"), _T("HELLO"), MB_OK);
return;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 在此放置代码。
unsigned ThreadId;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadProc, NULL, NULL, &ThreadId);
g_hWaitableTimer = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER liStartTime;
liStartTime.QuadPart = -(5 * 1000 * 1000 * 10);
SetWaitableTimer(g_hWaitableTimer, &liStartTime, 0, ApcCompletionRoutine, NULL, FALSE);
SleepEx(INFINITE, TRUE); // 关键
CloseHandle(hThread);
CloseHandle(g_hWaitableTimer);
MSG msg;
HACCEL hAccelTable;
// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WAITABLETIMERTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WAITABLETIMERTEST));
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
可等待计时器添加APC测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。