在使用MFC 定時器的時候,因為該定時器訊息回應優先級比較低。
有沒有大神,撰寫過像mfc的定時器,但是優先級要高。最后能后臺處理任務。
給個demo 謝謝了!
uj5u.com熱心網友回復:
Waitable Timer ObjectsA "waitable" timer object is a synchronization object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronization. A timer of either type can also be a periodic timer.
Object Description
manual-reset timer A timer whose state remains signaled until SetWaitableTimer is called to establish a new due time.
synchronization timer A timer whose state remains signaled until a thread completes a wait operation on the timer object.
periodic timer A timer that is reactivated each time the specified period expires, until the timer is reset or canceled. A periodic timer is either a periodic manual-reset timer or a periodic synchronization timer.
A thread uses the CreateWaitableTimer function to create a timer object. Specify TRUE for the bManualReset parameter to create a manual-reset timer and FALSE to create a synchronization timer. The creating thread can specify a name for the timer object in the lpTimerName parameter. Threads in other processes can open a handle to an existing timer by specifying its name in a call to the OpenWaitableTimer function. Any thread with a handle to a timer object can use one of the wait functions to wait for the timer state to be set to signaled.
The thread calls the SetWaitableTimer function to activate the timer. Note the use of the following parameters for SetWaitableTimer:
Use the lpDueTime parameter to specify the time at which the timer is to be set to the signaled state. When a manual-reset timer is set to the signaled state, it remains in this state until SetWaitableTimer establishes a new due time. When a synchronization timer is set to the signaled state, it remains in this state until a thread completes a wait operation on the timer object.
Use the lPeriod parameter of the SetWaitableTimer function to specify the timer period. If the period is not zero, the timer is a periodic timer; it is reactivated each time the period expires, until the timer is reset or canceled. If the period is zero, the timer is not a periodic timer; it is signaled once and then deactivated.
A thread can use the CancelWaitableTimer function to set the timer to the inactive state. To reset the timer, call SetWaitableTimer. When you are finished with the timer object, call CloseHandle to close the handle to the timer object.
uj5u.com熱心網友回復:
用多執行緒定時吧,既可以設定優先級又能比較準確的計時。uj5u.com熱心網友回復:
可等待定時器物件“等待”定時器物件是一個同步物件的狀態被設定為有信號時,由于到達指定時間。有兩種可等待定時器,可以創建:手動復位和同步。任一型別的定時器也可以是周期定時器。
物件描述
手動復位定時器,定時器的狀態仍然表示,直到setwaitabletimer稱為建立一個新的到期時間。
同步計時器:在執行緒完成定時器物件的等待操作之前其狀態保持信號的計時器。
周期計時器:每次指定的時間到期后重新啟動的計時器,直到定時器復位或取消為止。周期定時器是周期性手動復位定時器或周期性同步定時器。
一個執行緒使用createwaitabletimer函式來創建一個定時器物件。指定真的bmanualreset引數創建一個手動復位定時器和假創建一個同步定時器。創建執行緒可以在lptimername引數計時器物件指定一個名稱。其他行程中的執行緒可以開啟一個處理到一個現有的定時器指定名稱的openwaitabletimer函式呼叫。任何具有定時器物件句柄的執行緒都可以使用等待函式中的一個來等待定時器狀態設定為信號。
呼叫執行緒setwaitabletimer功能激活定時器。注意以下引數的使用SetWaitableTimer:
使用lpduetime引數指定時間的定時器被設定為終止狀態。當手動復位定時器被設定為信號狀態,保持在這個狀態直到setwaitabletimer建立了一個新的到期時間。當同步定時器設定為信號狀態時,它將保持在該狀態,直到執行緒在計時器物件上完成等待操作。
使用的setwaitabletimer功能期引數指定定時器周期。如果周期不是零,定時器是一個周期定時器,它被重新激活每次期限屆滿,直到定時器復位或取消。如果周期為零時,定時器不是周期性定時器,它會發出一次信號,然后停用。
一個執行緒可以使用cancelwaitabletimer函式來設定定時器到非活動狀態。重置計時器,叫setwaitabletimer。當你完成了定時器物件,呼叫CloseHandle關閉處理定時器物件。
uj5u.com熱心網友回復:
http://m.blog.csdn.net/article/details?id=8134064uj5u.com熱心網友回復:
提醒:Windows計時精度≈15ms轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/99764.html
標籤:進程/線程/DLL
