none
Elapsed Timer Event RRS feed

  • Question

  • Hello

    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?

    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? 

    Tuesday, April 24, 2018 8:08 PM

All replies

  • Hi,

    You should try using Timers. Simple timer can be a JavaScript timer. e.g. below timer executes every 5 second.

     setInterval(CheckNewMessage, 5000);

    function CheckNewMessage() {

    // Logic to executed every n seconds defined in set

    }

    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.

    Thanks,

    Nitin

    Tuesday, April 24, 2018 9:22 PM
  • I don't see why you need the stopwatch. Why not use a timer with an interval equal to the required timeout, which you pause while you are communicating and start again when you have finished?

    Or, if you really can't use a timer with that interval for some reason, save DateTime.Now when you stop communicating, and every ten seconds check the current time against the saved time. Still no need for a stopwatch.

    Wednesday, April 25, 2018 1:37 AM