L
Liam
Hi
Anyone else encountered this problem?
In a VB or C# project I have 2 forms. Both have a forms timer. The
timer in the one of the forms is running at 55ms and raises an event
which is handled by the first form. The handler disables, sets the
interval, then re-enables the timer on its form. It also sleeps for 60
ms.
The problem I've found occurs when the 55ms time overruns (say when
the computer is doing something else ). After the timer has been
re-enabled the first timer tick ( the one raising the event ) is
called again even though the first instance is still running. Hence
the call stack looks like this
Tick1()
RaiseEvent
...
Re-enable timer
Tick()
The key here is the re-enabling of the first timer. If that is not
done then the problem does not occur.
Anyone else encountered this? It can't be considered normal behaviour
for the timer tick can it?
thanks for any input
Liam
More detailed code follows
Public Class DialogForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Event DialogEvent()
Private Sub DialogForm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Timer1.Enabled = False
End Sub
Dim b As Boolean = False
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If b = True Then
ErrorLabel.Text = Str(Val(ErrorLabel.Text) + 1)
End If
b = True
RaiseEvent DialogEvent()
b = False
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub DialogButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DialogButton.Click
Dim f As New DialogForm
AddHandler f.DialogEvent, AddressOf DialogEventHandler
'f.ShowDialog()
f.Show()
End Sub
Sub DialogEventHandler()
Sleep(50)
Timer1.Enabled = False
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
End Class
Anyone else encountered this problem?
In a VB or C# project I have 2 forms. Both have a forms timer. The
timer in the one of the forms is running at 55ms and raises an event
which is handled by the first form. The handler disables, sets the
interval, then re-enables the timer on its form. It also sleeps for 60
ms.
The problem I've found occurs when the 55ms time overruns (say when
the computer is doing something else ). After the timer has been
re-enabled the first timer tick ( the one raising the event ) is
called again even though the first instance is still running. Hence
the call stack looks like this
Tick1()
RaiseEvent
...
Re-enable timer
Tick()
The key here is the re-enabling of the first timer. If that is not
done then the problem does not occur.
Anyone else encountered this? It can't be considered normal behaviour
for the timer tick can it?
thanks for any input
Liam
More detailed code follows
Public Class DialogForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Event DialogEvent()
Private Sub DialogForm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Timer1.Enabled = False
End Sub
Dim b As Boolean = False
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If b = True Then
ErrorLabel.Text = Str(Val(ErrorLabel.Text) + 1)
End If
b = True
RaiseEvent DialogEvent()
b = False
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub DialogButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DialogButton.Click
Dim f As New DialogForm
AddHandler f.DialogEvent, AddressOf DialogEventHandler
'f.ShowDialog()
f.Show()
End Sub
Sub DialogEventHandler()
Sleep(50)
Timer1.Enabled = False
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
End Class