when users feel that the software is easy to use, they can do some work on a regular basis without involvement. For example, update the virus database regularly every day, regularly download movies, and regularly update characters in the game. To implement these functions, you can use the API functions createwaitabletimer and setwaitabletimer of the timer to implement them. This is more accurate for the clock created by the API function, and can reach 100 times the second of the second.
the createwaitabletimer and setwaitabletimer functions are declared as follows:
winbaseapi
__ out
handle
winapi
createwaitabletimera (
_ in_opt lpsecurity_attributes lptimerattributes,
_ in bool bmanualreset,
_ in_opt lpcstr lptimername
);
winbaseapi
__ out
handle
winapi
createwaitabletimerw (
_ in_opt lpsecurity_attributes lptimerattributes,
_ in bool bmanualreset,
_ In_opt lpcwstr lptimername
);
# ifdef Unicode
# define createwaitabletimer createwaitabletimerw
# else
# define createwaitabletimer createwaitabletimera
# endif //! Unicode
The F m a n u a l r e s e t parameter is used to specify a manually reset timer or an automatically reset timer.
When a manual reset timer signal is sent, all threads waiting for the timer become schedulable threads. When sent from
When a reset timer signal is notified, only one waiting thread changes to a schedulable thread.
Winbaseapi
Bool
Winapi
Setwaitabletimer (
_ In handle htimer,
_ In const large_integer * lpduetime,
_ In long lperiod,
_ In_opt ptimerapcroutine pfncompletionroutine,
_ In_opt lpvoid lpargtocompletionroutine,
_ In bool fresume
);
Lptimerattributes is the attribute used to set the timer.
Whether to manually reset bmanualreset.
Lptimername is the name of the timer.
Htimer is the timer handle.
Lpduetime is used to set the timer time interval. When set to positive, it is absolute time; when set to negative, it is relative time.
Lperiod is a period.
Pfncompletionroutine is the set callback function.
Lpargtocompletionroutine is the parameter sent to the callback function.
Fresume is used to set whether the system is automatically restored.
An example of calling a function is as follows:
#001 // create a timer
#002
#003 int createtesttimer (void)
#004 {
#005 handle htimer = NULL;
#006 large_integer liduetime;
#007
#008 // set the relative time to 10 seconds.
#009 liduetime. quadpart =-100000000;
#010
#011 // create a timer.
#012 htimer = createwaitabletimer (null, true, _ T ("testwaitabletimer "));
#013 if (! Htimer)
#014 {
#015 return 1;
#016}
#017
#018 outputdebugstring (_ T ("10-second timer \ r \ n "));
#019
#020 // set to 10 seconds.
#021 if (! Setwaitabletimer (htimer, & liduetime, 0, null, null, 0 ))
#022 {
#023 //
#024 closehandle (htimer );
#025 return 2;
#026}
#027
#028 // The timer has a signal.
#029 if (waitforsingleobject (htimer, infinite )! = Wait_object_0)
#030 {
#031 outputdebugstring (_ T ("10 seconds timer error \ r \ n "));
#032 //
#033 closehandle (htimer );
#034 return 3;
#035}
#036 else
#037 {
#038 // 10 seconds.
#039 outputdebugstring (_ T ("10 seconds timer reached \ r \ n "));
#040}
#041
#042 //
#043 closehandle (htimer );
#044 return 0;
#045}