如何在C ++控制台应用程序中创建计时器?
问题描述:
你好,人们..在控制台中,我们做了不同的事情,例如打印值,但是如果我们想放置计时器来更改值,我们应该怎么做.假设在约翰程序中数组中有5个5个值[] = {1,2,3,4,5)并在调试后弹出数字1,对于数字2大约需要30秒左右..好吧,就是这样,我们应该可以放在我们打印的值之间设置计时器?
hello,people.. in console ,there are different things that we do,like printing the values but what should we do if we want to put the timer for changing the values.suppose in program john has 5 five values in array[]={1,2,3,4,5) and after debugging,number 1 pops up and for number 2 it should take like 30 second or so on..well,just thing is ,there we should be able to put timer between the values we print???
答
使用CreateWaitableTimer [使用等待的计时器对象 [ ^ ]
Use the CreateWaitableTimer[^] function.
Also take a look at Using Waitable Timer Objects[^]
创建线程并在指定的时间内休眠,然后执行作业
void ThreadProc(void * pdata)
{
//处理任务
///计时器像计时器一样工作.
睡眠(100)
}
Create a thread and Sleep for a specified time and execute the job
void ThreadProc( void *pdata)
{
// Work with a task
/// Timer to work like a timer.
Sleep( 100 )
}