![]() |
|||
Vb .net timer problem with Windows 7 dual processors
By: rekha singh | 22 May 2010 4:52 pm
Hello Everyone, I have been writing visual basic and vb .net applications for years and have come across this problem while upgrading from Windows Xp to Windows 7.
First let me explain the application then what it does on 4 different computers, the hardware and software I used. The application is written in Visual Studio 2005 VB .net framework 2. I is a very simple photo timer program that allows you to set a time in hours, minutes and seconds the start a count down to 0 that will play a sound file.
I use 2 timers, timer1 is set to an interval of 1000 and updates the count down text every second. Timer2 is set to the interval of the time for the counter, for example a 1 minute time is an interval of 60000. I checked the running of timer2 with a clock and it works fine. However timer1 will be behind by increasing amounts as the program runs. It will always be slow by 6 seconds in 500 seconds for example. This only happens on Windows 7 with a dual processor system.
Here is what works and does not work.
Windows Xp works always, even when running virtual pc under Windows 7.
Windows 7 works on Pentium 4 system.
Windows 7 fails on Pentium E6500 dual core system.
Windows 7 fails on IBM Lenovo R61i Pentium dual core T2370.
I wrote a simpler test program and it does the exact same thing.
Changed the timer to system.timer. timer and it did not change the problem.
Here is the code with the system.timer
Public Class Form1
Dim I = 0
Dim Running As Boolean = False
Private t As New System.Timers. Timer(1000)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load#
AddHandler t.Elapsed, AddressOf TimerDone
t.Interval = 1000
t.SynchronizingObje ct = Me
End Sub
Public Sub TimerDone(ByVal sender As Object, ByVal e As System.Timers. ElapsedEventArgs )
I = I - 1
Label1.Text = I
End Sub
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Running = False Then
Label2.Text = ""
Button1.Text = "Stop"
TrackBar1.Enabled = False
Timer2.Interval = Label1.Text * 1000
I = (Timer2.Interval / 1000) - 1
t.Enabled = True
Timer2.Enabled = True
Running = True
Else
'Timer1.Enabled = False
Timer2.Enabled = False
t.Enabled = False
TrackBar1.Enabled = True
Button1.Text = "Start"
Label2.Text = "Stopped"
Running = False
End If
End Sub
Private Sub Timer2_Tick( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Timer1.Enabled = False
Timer2.Enabled = False
t.Enabled = False
Button1.Text = "Start"
I = 0
Label2.Text = "Done"
TrackBar1.Enabled = True
Button1.Text = "Start"
Running = False
End Sub
Private Sub TrackBar1_Scroll( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Label1.Text = TrackBar1.Value
End Sub
End Class
Thanks for any ideas.
|
