在 WaitOne 超时之前,计时器事件不会触发
我有一个定期触发以检查新数据的计时器。有时,我需要立即触发计时器,并且需要等待计时器处理程序完成其操作后再继续。我尝试让处理程序设置一个 AutoResetEvent,然后我的主线程将等待该事件,但这不起作用。直到我对 WaitOne 的调用超时后,计时器才会触发。我尝试使用 System.Timers.Timer 和 System.Threading.Timer 得到相同的结果。关于我做错了什么有什么想法吗?
I have a timer that fires periodically to check for new data. Occasionally, I need the timer to fire immediately and I need to wait for timer handler to do its thing before continuing. I tried having the handler set an AutoResetEvent that my main thread would then wait on but this did not work. The timer would not fire until after my call to WaitOne timed out. I have tried using System.Timers.Timer and System.Threading.Timer with the same results. Any ideas as to what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论