Async friendly DispatcherTimer wrapper/subclass

Posted by Simon_Weaver on Stack Overflow See other posts from Stack Overflow or by Simon_Weaver
Published on 2012-09-15T21:11:03Z Indexed on 2012/09/15 21:38 UTC
Read the original article Hit count: 780

I have a DispatcherTimer running in my code that fire every 30 seconds to update system status from the server. The timer fires in the client even if I'm debugging my server code so if I've been debugging for 5 minutes I may end up with a dozen timeouts in the client. Finally decided I needed to fix this so looking to make a more async / await friendly DispatcherTimer.

  • Code running in DispatcherTimer must be configurable whether it is reentrant or not (i.e. if the task is already running it should not try to run it again)
  • Should be task based (whether or not this requires I actually expose Task at the root is a gray area)
  • Should be able to run async code and await on tasks to complete
  • Whether it wraps or extends DispatcherTimer probably doesn't really matter but wrapping it may be slightly less ambiguous if you don't know how to use it
  • Possibly expose bindable properties for IsRunning for UI

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf