问题描述
您好
我有一个我需要与之交谈的网站,如果它超过了X的数量自从我上次与之谈话以来的时间。我最初的想法是设置一个秒表并在我与网页通信后重置它。 我想过设置Timer的
事件来检查秒表的经过时间,每10秒钟一次。 我认为这样可行,但是当经过的时间达到所需的超时值时,是不是有更好的方法可以触发事件?
I've got a website that I need to talk to, if it's been more then X amount of time since I last talked to it. My initial thought is to setup a stopwatch and reset it after I communicate with the webpage. I'd thought about setting up Timer intenal event to check the elapsed time of the stopwatch, every 10 seconds. I think that would work, but isn't there a better way to have an event fired when the elapsed time meets the required timeout value?
有了计时器的想法,我会设置间隔事件为10秒。 听起来不错,但每10秒钟我需要检查一下经过的时间。 似乎没必要。 也许这是正确的方法,但是如果在没有额外计时器的情况下达到最后一次通信
时间阈值时,我可能会触发一个事件吗?
With the timer idea, I'd set the interval event to 10 seconds. Sounds good, but every 10 seconds I'd need check the elapsed time. Seems unnecessary. Maybe that is correct way, but could I just have an event fired when the last communication time threshold is reach without the additional timer?
推荐答案
您应该尝试使用计时器。简单计时器可以是JavaScript计时器。例如低于计时器每5秒执行一次。
You should try using Timers. Simple timer can be a JavaScript timer. e.g. below timer executes every 5 second.
功能 CheckNewMessage(){
//在集合中定义的每n秒执行的逻辑
}
如果要在服务器端进行编码,可以使用C#计时器并使用其timer_elapsed事件。简单的JavaScript计时器应该符合您的目的。
If you want to code on server side, you can use C# timer and use its timer_elapsed event. Simple JavaScript timer should serve your purpose.
谢谢,
Nitin
这篇关于经过的计时器事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!