G
Guest
I have a simple problem:
In calling form:
Private _theForm As MyFormClass()
' in a button click event...
If theForm Is Nothing Then
theForm = New MyFormClass()
End If
theForm.Show()
The problem is if I close theFrom, then click the button of the calling form again, theForm Is Nothing will evaluate to False (meaning it's a valid reference), yet when theForm.Show() executes, I get an exception "Cannot access disposed object named 'theForm'"
Even if I call Dispose on the called form when it's closed, the problem doesn't go away. I thought it was just some garbage collection issue but calling GC.Collect/WaitForPendingFinalizers before theForm.Show() does not make any difference.
As a workaround, I could trap the exception in a try block but I was hoping for a more elegant solution, like simply inspecting a property. In the first place, why does theForm Is Nothing evalute to False when the form is already closed/disposed?
Many thanks =)
In calling form:
Private _theForm As MyFormClass()
' in a button click event...
If theForm Is Nothing Then
theForm = New MyFormClass()
End If
theForm.Show()
The problem is if I close theFrom, then click the button of the calling form again, theForm Is Nothing will evaluate to False (meaning it's a valid reference), yet when theForm.Show() executes, I get an exception "Cannot access disposed object named 'theForm'"
Even if I call Dispose on the called form when it's closed, the problem doesn't go away. I thought it was just some garbage collection issue but calling GC.Collect/WaitForPendingFinalizers before theForm.Show() does not make any difference.
As a workaround, I could trap the exception in a try block but I was hoping for a more elegant solution, like simply inspecting a property. In the first place, why does theForm Is Nothing evalute to False when the form is already closed/disposed?
Many thanks =)