locked
Timers under Windows 7 dual core processors has problems RRS feed

  • Question

  • Hello,

    After I upgraded from Windows Xp to Windows 7 on any dual core cpu machine my programs that use a simple timer function run incorrectly.  The program works with the exact same hardware under Windows Xp and Windows Server 2003.  I am using Visual Studio 2005 to write .NET Visual Basic programs that use 2 timers to count down.  The first timer, timer1, is set to a value say 150000 ms (150 seconds).  The second timer, timer2, is set to 1000ms (1 second).  Both timers are enabled one right after the other from a button click event and begin.  The timer2 routine running every second updates a label counting down the seconds.  When timer1 fires it disables itself and exits.  Timer2 also checks to see if timer1 is still running if it is not it will stop.  Under Windows Xp and Windows Server 2003 the resulting count in the label is 0 when timer2 detects timer1 has finished.  Under Windows 7 when timer1 stops timer2 is not at 0 it is 3 for 150 seconds and gets larger the more timer1 is increased.  It appears to me timer2 is not being fired every 1000ms as it was under Windows Xp.  I have not found anything to explain this and am asking if anyone know about this problem.

    I have included the Visual Basic code below.  If you want to test it just run Visual Studio and create a new project.  Put the buttons, numericupdown, and labels in your form and past my code into the correct buttons.  I have used these type of timer events for years without any problems unit Windows 7.  

    Windows 7 on a single core Pentium 4 with hyperthreading turned on works fine.

    Windows 7 on a dual core E6500 fails, Windows Server 2003 works.

     

    Public Class Form1
        Dim I As Integer

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            I = NumericUpDown1.Value
            Timer1.Interval = I * 1000
            Timer2.Interval = 1000
            Label1.Text = I
            Timer1.Enabled = True
            Timer2.Enabled = True
            Label2.Text = "Timer1 running"

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Timer1.Enabled = False
            Timer2.Enabled = False
            Label2.Text = "Timer1 stopped"

        End Sub

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Enabled = False

        End Sub

        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            If Timer1.Enabled = False Then
                Timer2.Enabled = False
                Label2.Text = "Timer1 done, count should be 0"
            End If
            I = I - 1
            Label1.Text = I

        End Sub

    End Class

    Wednesday, August 25, 2010 7:36 PM

Answers

  • Hi,

     

    This is more development related. I suggest post a thread in our MSDN forum for discuss:

     

    Microsoft Visual Studio General Forums

     

    Regards,

     

    Sabrina

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by Sabrina Shen Tuesday, August 31, 2010 8:27 AM
    Friday, August 27, 2010 9:05 AM