user1785715 user1785715 - 1 year ago 140
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.

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download