I have tried Dispatcher timer but it doesn't seem to be working correctly.
I have the tick event set up that adds to a tick counter every tick and it's just not doing the job right. I also have a Stopwatch to count how long it's been, and the numbers aren't matching up. Please let me know what kind of solution would work to give me 192 ticks each second.
Stopwatch sw = new Stopwatch();
public DispatcherTimer dt = new DispatcherTimer();
dt.Tick += dt_Tick;
dt.Interval = TimeSpan.FromMilliseconds(1000/192);
dt.Start();
sw.Start();
void dt_Tick(object sender, EventArgs e)
{
tick_textbox.Text = tick_counter.ToString();
seconds_textbox.Text = sw.Elapsed.ToString();
tick_counter++;
}
Now, I've lowered it to 8 per second, which should solve the resolution problem, but I'm getting wildly different outcomes from using an interval of TimeSpan.FromSeconds and TimeSpan.FromMilliseconds:
dt.Tick += dt_Tick;
dt.Interval = TimeSpan.FromSeconds(2 / 16);
dt.Start();
vs.
dt.Tick += dt_Tick;
dt.Interval = TimeSpan.FromMilliseconds(2000 / 16);
dt.Start();
What is the reason for that?