DispatchTimer - Prevent the tick event to be triggered if the previous tick is still running

后端 未结 4 2037
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 13:56

In a Silverlight app, I have a block of code that has to run every 500ms. I am planning o use a DispatcherTimer to achieve this (see code below).

Dispatcher         


        
4条回答
  •  不要未来只要你来
    2021-01-19 14:32

    I would say you skip a tick if it takes too long, otherwise you will get a huge queue because of the lock.

    So in the eventhandler say:

    if(!busy) {
      busy = true;
    
      // some code which could take longer than 500 ms
    
      busy = false;
    }
    

提交回复
热议问题