Hello all.
I have a simple application that I was using to test and understand
the System.Timers.T imer and noticed that when I stop the application,
on occasion, it throughs the following exception.
An exception of type 'System.ObjectD isposedExceptio n' occurred in
System.Windows. Forms.dll but was not handled in user code
Additional information: Cannot access a disposed object.
Should I just place the offending line in a Try Catch or set the timer
to nothing in FormClosing. Below is the code, real short.
Public Class formMain
Dim c As New Chronology
Dim WithEvents UpdateTmr As System.Timers.T imer
Dim StartTime As Date
Dim BlockWindowStar t As Date
Dim BlockWindowEnd As Date
Private Sub formMain_Load(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
UpdateTmr = New System.Timers.T imer
UpdateTmr.Inter val = 1000
UpdateTmr.Enabl ed = True
StartTime = DateTime.Now
BlockWindowStar t = StartTime.AddSe conds(10)
BlockWindowEnd = BlockWindowStar t.AddSeconds(10 )
End Sub
Private Sub UpdateTmr_Elaps ed(ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles UpdateTmr.Elaps ed
'Exception is thrown
here.<<<<<<<<<< <<<<<<<<<<<<<<< <<<<<<<<<<<<<<< <<<<<<
Me.Invoke(New delUpdateForm(A ddressOf UpdateForm))
End Sub
Public Delegate Sub delUpdateForm()
Public Sub UpdateForm()
Label1.Text = Now
Dim x As DateTime = DateTime.Now
Dim tsw As TimeSpan = BlockWindowEnd - BlockWindowStar t
Debug.Print("Bl ock Window Value: " & tsw.Ticks)
Dim ts As TimeSpan = DateTime.Now - BlockWindowStar t
Debug.Print(ts. Ticks)
Debug.Print(Dat eTime.Now >= BlockWindowStar t And DateTime.Now
<= BlockWindowEnd)
End Sub
End Class
I have a simple application that I was using to test and understand
the System.Timers.T imer and noticed that when I stop the application,
on occasion, it throughs the following exception.
An exception of type 'System.ObjectD isposedExceptio n' occurred in
System.Windows. Forms.dll but was not handled in user code
Additional information: Cannot access a disposed object.
Should I just place the offending line in a Try Catch or set the timer
to nothing in FormClosing. Below is the code, real short.
Public Class formMain
Dim c As New Chronology
Dim WithEvents UpdateTmr As System.Timers.T imer
Dim StartTime As Date
Dim BlockWindowStar t As Date
Dim BlockWindowEnd As Date
Private Sub formMain_Load(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
UpdateTmr = New System.Timers.T imer
UpdateTmr.Inter val = 1000
UpdateTmr.Enabl ed = True
StartTime = DateTime.Now
BlockWindowStar t = StartTime.AddSe conds(10)
BlockWindowEnd = BlockWindowStar t.AddSeconds(10 )
End Sub
Private Sub UpdateTmr_Elaps ed(ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles UpdateTmr.Elaps ed
'Exception is thrown
here.<<<<<<<<<< <<<<<<<<<<<<<<< <<<<<<<<<<<<<<< <<<<<<
Me.Invoke(New delUpdateForm(A ddressOf UpdateForm))
End Sub
Public Delegate Sub delUpdateForm()
Public Sub UpdateForm()
Label1.Text = Now
Dim x As DateTime = DateTime.Now
Dim tsw As TimeSpan = BlockWindowEnd - BlockWindowStar t
Debug.Print("Bl ock Window Value: " & tsw.Ticks)
Dim ts As TimeSpan = DateTime.Now - BlockWindowStar t
Debug.Print(ts. Ticks)
Debug.Print(Dat eTime.Now >= BlockWindowStar t And DateTime.Now
<= BlockWindowEnd)
End Sub
End Class
Comment