user1785715 user1785715 - 1 month ago 7x
C# Question

Millisecond interval for DispatcherTimer

I'm using a DispatcherTimer to call a void in C#:

counter = new System.Windows.Threading.DispatcherTimer();
counter.Tick += new EventHandler(counter_Tick);
counter.Interval = new TimeSpan(0, 0, 1);

However I would like the interval to be a few milliseconds, TimeSpan's parameters are hours,minutes,seconds and only accepts integers (as far as I can see). Is there a work around for DispatcherTimer? I've tried Timer but I cannot use it (missing reference apparently)

Thanks in advance.


The TimeSpan object has a constructor that takes milliseconds as a parameter:

MSDN has the details:

Basically, replace new TimeSpan(0, 0, 1) with new TimeSpan(0, 0, 0, 0, millisecondTimeout).