ETA: Environment.TickCount を使用しても、同じ問題は発生しません。
ETA2: アプリで実際に Forms.Timer を使用していないことを追加する必要があります。これは、高頻度のタイマーの使用を無効にするためです。ここでは、コードを単純化するために使用しました。
ETA3: 以下の回答として回避策を公開しました。
I'm having problems with the StopWatch class that I'm observing on a laptop with XP but not a different laptop with Win7. Here's the test code:
Public Class FormTest
Inherits Form
Private WithEvents Timer1 As System.Windows.Forms.Timer = New System.Windows.Forms.Timer
Private sw As Stopwatch = New Stopwatch
Public Sub New()
Me.Timer1.Interval = 1
End Sub
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
Me.sw.Start()
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Text = sw.ElapsedMilliseconds.ToString
Me.Update()
End Sub
End Class
On windows 7, checking the ellapsed milliseconds every second, I get something like:
0, 1010, 2030, 3005 ...
On XP, I get something like: 0, 200, 306, 390, 512, ...
That is, it is way off. We're not talking about milliseconds. It's nothing to do with whether the timer is high resolution, as that reports as true. As far as I know it's nothing to do with processor affinity as I've tried setting that to each of the 2 processors.
As I say, I think this is to do with XP, but it could be to do with the different cores - both laptops are, however, intel.