可等待計時器

2021-05-25 05:43:16 字數 1392 閱讀 2309

該核心物件類似於計時器。當然,它和使用者模式下的計時器是有區別的。

使用createwaitabletimer函式可以建立乙個可等待計時器核心物件。用setwaitabletimer函式來對可等待計時器核心物件進行設定。另外可等待計時器核心物件還可以以非同步(asynchronous)方式呼叫函式(apc)。基本上都可以給它傳遞null。

我比較喜歡使用事件核心物件和可等待計時器核心物件配合使用。否則前面學習的計時器核心物件就白學了:-)。

下面給出沒有任何注釋的**,因為**很簡單,很容易看懂,這是在windows live writer中寫的,所以沒有**模式:

#include

#include

lresult callback wndproc(hwnd,uint,wparam,lparam);

hwnd g_hwnd;

handle g_htimer,g_hevt;

dword winapi wtthreadwatch(pvoid pvparam)

; g_hevt=createevent(null,false,false,null);

while(true)

return 0;

} dword winapi wtthreadactive(pvoid pvparam)

else }

return 0;

} int winapi _twinmain(hinstance hinstance,hinstance,ptstr,int)

if(!g_hwnd)

showwindow(g_hwnd,sw_shownormal);

updatewindow(g_hwnd);

msg msg;

while(getmessage(&msg,null,0,0))

return msg.wparam;

} lresult callback wndproc(hwnd hwnd,uint nmsg,wparam wparam,lparam lparam)

; filetime ftlocal,ftutc;

large_integer litime;

switch(nmsg)

return defwindowproc(hwnd,nmsg,wparam,lparam);

}

可等待的計時器與APC呼叫

以前第一次看到apc,也就是非同步過程呼叫的時候,沒有搞明白這是乙個什麼樣的機制。今天再看一次,然後結合一些簡單的測試 和搜尋來的資料,大概明白了是怎麼回事。先來非常簡單地描述一下這乙個 可等待的計時核心物件 大概定義如下 可等待的計時器物件是這樣一種核心物件,它們會在某個指定的時間觸發,或每一段時...

python計時器 python 計時器

import sysclassshowtime qwidget def init self super init self.istimestart false 標記時間是否開始計時 self.setwindowtitle qlable 顯示計時時間 self.lable time val qlabe...

python計時器單位 python計時器類

import time as t class mytimer def init self self.unit 年 月 日 時 分 秒 self.prompt 未開始計時 self.lasted self.start 0 self.stop 0 def str self return self.pro...