3
votes

I have a program that is a Windows Forms C# .NET 4.0 Framework Client Profile. The only thing it does is update a bitmap image on a Quicktime control on the form every 5500 milliseconds using a windows form timer. On my development laptop I am using System 8.1 and it is an i7 processor with a SSD drive. I am using VS 2012. I am using the .NET Stopwatch object to time my events on my development laptop. On my laptop with the forms timer set to 5500 I get tick events very close to 5500 ms with +/- 15 ms accuracy which is more than good enough (I'd be satisfied with 50 ms accuracy).

When I run the exact same program on the production computers which are i3 and i5 processors and System 7 windows machines the tick event is always 5700 ms with +/- 15 ms accuracy - in other words the tick event is always 200 ms long, but still always very exactly 200 ms long with +/- 15ms accuracy, it is almost like the timer interval is set to 5700 ms on the production machines - but it is the same code?

Does anyone have any ideas on how this could be possible and where to look for why this is occurring?

1
If you need higher resolution I would recommend going with a System.Timers.Timer instead. The forms timer goes through the message queue and can be delayed. - itsme86
There's no simple explanation, 200 ms is not even a nice multiple of 15.625. You'll need to investigate deeper, focusing on why Stopwatch doesn't match Environment.TickCount and/or why the UI thread could be slow to respond to the notification. - Hans Passant
I will investigate deeper per Hans Passant - I don't really need accuracy less than 50 ms hence my choice for forms.timer. I initially thought that forms.timer could not be worse than about 55 ms but that is not true it can be much worse if the UI is busy. I will give correct answer to etr below as I may have to look at one of the other timers to correct this discrepancy? - Neal Davis

1 Answers

0
votes

System.Windows.Forms.Timer may not be your best option since it only runs on your UI thread at idle time. System.Timers.Timer or System.Threading.Timer could overall give you better results with less dependency to processor speed. See this article for more detailed comparison.