在计时器之前设置timesetevent事件 [英] Set the timesetevent event before the timer

查看:108
本文介绍了在计时器之前设置timesetevent事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试更改时间驱动的应用程序来实现事件驱动



原始应用程序使用timeSetEvent函数为计时器创建一个线程,每次达到计时器的延迟时间时,回调程序被激活



我想要发信号通知计时器的线程,这样它就会在

达到延迟时间之前激活回调



有没有办法改变计时器线程为了添加一个事件

等待而不仅仅是计时器?



还有其他解决方案吗?问题?



谢谢



dj



我尝试了什么:



从外部调用回调 - 但它对原始代码进行了重大更改

Hi,

I am trying to change an application which is time driven to be event driven

The original application uses the timeSetEvent function which creates a thread for the timer and every time the delay duration of the timer is reached the callback procedure is activated

I want to signal the thread of the timer so it would activate the callback before the
the delay duration is reached

Is there a way to change the timer thread in order to add an event
to be waited to and not just the timer?

Is there any other solution to this problem?

Thanks

dj

What I have tried:

Calling the callback from outside - but its a big change of the original code

推荐答案

你没有告诉我们你的线程类型(比如Windows) theads或Linux pthread)。



但我认为你的线程已经在检查诸如停止(终止应用程序时)或启动和重置计时器等事件。如果是这样,只需实现另一个只在触发时调用回调函数的事件。



如果没有,我建议至少停止这样做。当您的应用程序终止时,它也应该停止所有子线程。否则这些将一直运行直到自己返回。



使用Windows WaitForSingleObject resp。 WaitForMultipleObjects的。使用pthreads使用 pthread_cond_wait pthread_cond_timedwait 。您还可以使用这些函数的超时值来实现计时器(如果还没有这样做的话)。



实现停止事件通常包含在有关特定内容的教程中线程类型。一旦使用了这个,为其他目的添加另一个事件非常简单。
You did not told us about the kind of your threads (like Windows theads or Linux pthread).

But I assume that your thread is already checking for events like stop (when terminating the application) or for starting and resetting the timer. If so, just implement another event that simply calls the callback function when triggered.

If not, I suggest to do so at least for stopping. When your application terminates it should also stop all child threads. Otherwise those would run until returning by themself.

With Windows use WaitForSingleObject resp. WaitForMultipleObjects. With pthreads use pthread_cond_wait or pthread_cond_timedwait. You can also use the timeout value of those functions to implement the timer (if not already doing so).

Implementing a stop event is usually covered by tutorials about a specific thread type. Once using such, adding another event for other purposes is quite simple.


这篇关于在计时器之前设置timesetevent事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆