本文介绍了C ++中的计时器问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试编写一个Callback函数,其中使用WaveInOpen和CALLBACK_EVENT和WaitForSingleObject.假设我有两个缓冲区要填充,当缓冲区被填充时,WaitForSingleObject将其接收.但是以某种方式,我认为我必须使用计时器,这样我才能知道何时缓冲区已满.我的问题是现在是否存在安全功能或以秒/毫秒为单位处理计时器的东西?我要使用计时器的代码部分是这样的.我已用粗体字母标记注释. int j = 0; waveInStart(); while(j< 2)//要填充的缓冲区数 { //这里我要使用计时器以秒/毫秒为单位填充指定的缓冲区////当缓冲区被填充时,应将缓冲区传递给WaitForSingleObject,计时器应重新启动并填充下一个缓冲区 j ++; dwWaitResult = WaitForSingleObject(event,INFINITE); switch(dwWaitResult) WAIT_OBJECT_0: ..... 默认值: printf(等待错误(%d)\ n",GetLastError()); } } 我尝试使用while函数来充当这样的计时器. GetLocalTime(& lt); int s = lt.wSecond + RecLength; if(s> = 60)//如果s> = 60秒,则减少60秒,这样秒数就正确了 s = s-60; while(lt.wSecond!= s +1)//录制继续直到指定时间达到RecLength GetLocalTime(& lt); dwWaitResult = WaitForSingleObject(event,INFINITE); ........ ..... 我真的不能与WaitForSingleObject一起完成这项工作.有人对我如何解决计时器问题有很好的主意吗?I am trying to write a Callbackfunction where i use WaveInOpen and CALLBACK_EVENT and WaitForSingleObject. Assume that i have two buffers to fill and when a buffer is filled the WaitForSingleObject take it. But in somehow i think i have to use a timer so i know when a buffers is filled. My question is now if there exist a safe function or something that handle a timer in seconds/milliseconds? The part of my code where i want to use the timer is like this. I have marked the comments with thick letters.int j = 0;waveInStart(); while(j < 2) //number of buffers to fill { //here i want to use a timer to fill the specified buffer in seconds/milliseconds //when the buffer is filled the buffer should be passed to WaitForSingleObject and the timer should restart and fill next buffer j++; dwWaitResult = WaitForSingleObject(event, INFINITE); switch(dwWaitResult) { case WAIT_OBJECT_0: ..... default: printf("Wait error (%d)\n", GetLastError()); } }I have tried to use a while function that will act as a timer like this.GetLocalTime(<); int s = lt.wSecond + RecLength; if(s >= 60) // if s >= 60 seconds, reduce it with 60 so the seconds will be right s = s - 60; while(lt.wSecond != s + 1) // The recording continues until the specified time reach RecLength GetLocalTime(<);dwWaitResult = WaitForSingleObject(event, INFINITE);.............I can´t really get this work either together with WaitForSingleObject.does anyone have any good idea of how i can solve the timer problem so it works together with WaitForSingleObject?推荐答案 这篇关于C ++中的计时器问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 06:30