
Cannot access disposed object named (Splash Screen related problem)
Quote:
> The following code successfully displays a splash screen and loads a
> second form. The method I am using is for the splash form to hide
> itself, load the second form, and have the entire program unload when
> the exit button is clicked on the second form. (The splash screen is
> programmed to unload via a timer which I have set through the
> property controls.) When the program terminates, it ends with an
> exception error:
> "Cannot access disposed object named 'Form2'."
> Posted below is the relevant code from the splash form. Form2 just
> does an me.close to finish up. How can I fix this? Thank you!
> Public Class Splash
> Inherits System.Windows.Forms.Form
> #Region " Windows Form Designer generated code "
> Dim Form2 As New Form2()
> Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e
> As
> System.EventArgs) Handles Timer1.Tick
> Me.Hide()
> Form2.Show()
> End Sub
> Private Sub Splash_Load(ByVal sender As System.Object, ByVal e
> As
> System.EventArgs) Handles
> MyBase.Load
> End Sub
> End Class
Add
Timer1.Enabled = False
after showing Form2.
Otherwise the following happens: When closing Form2, it is disposed. After
that, the timer of Form1 still ticks and Form2.Show is called again. As the
variable Form2 still points to the same instance, the one that is disposed
now, Form2.Show leads to this exception.
--
Armin