首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > windows >

Chapter11-"windows线程池"之 间距执行函数

2013-01-28 
Chapter11-windows线程池之 间隔执行函数按照一定的时间间隔,周期性调用某个函数,大致需要用到以下五步

Chapter11-"windows线程池"之 间隔执行函数

     按照一定的时间间隔,周期性调用某个函数,大致需要用到以下五步

    按照一定的时间间隔,周期性被调用的TimerCallback函数的原型如下
    #include <windows.h>#include <tchar.h>#include <stdio.h>#include <time.h>VOID CALLBACK TimeoutCallback(                              PTP_CALLBACK_INSTANCE   pInstance,                              PVOID                   pvContext,                              PTP_TIMER               pTimer                             ){    time_t now_time;    now_time = time(NULL);    struct tm *tblock;    tblock = localtime(&now_time);    printf("Local time is: %s",asctime(tblock));  }void main(){    // Create the threadpool timer object    PTP_TIMER lpTimer =         CreateThreadpoolTimer(TimeoutCallback, NULL, NULL);    // Start the timer in one second to trigger every 1 second    ULARGE_INTEGER ulRelativeStartTime;    ulRelativeStartTime.QuadPart = (LONGLONG) -(10000000);  // start in 1 second    FILETIME ftRelativeStartTime;    ftRelativeStartTime.dwHighDateTime = ulRelativeStartTime.HighPart;    ftRelativeStartTime.dwLowDateTime  = ulRelativeStartTime.LowPart;    SetThreadpoolTimer(        lpTimer,         &ftRelativeStartTime,         1000, // Triggers every 1000 milliseconds        0        );    getchar();    WaitForThreadpoolTimerCallbacks(lpTimer, FALSE);    // Clean up the timer    CloseThreadpoolTimer(lpTimer);        printf("ThreadpoolTimes is closed!\n");    getchar();    }
    《windows核心编程》(笔记)系列文章是本人看《windows核心编程》时的一些学习笔记,有疏忽之处,欢迎各位网友指正。QQ邮箱:job.zhanghui@qq.com

热点排行