active said:
So immediately after I do a dispose I might still be able to access the
object. That's a surprise.
I understand that the GC may not happen for some time but it's anybody
guess what dispose may have done to the object.
Just to refresh, the original question was why does the second
OpenFileDialog work after the object has been disposed. The GC lines were
only there because I did cut - paste.
'OpenFileDialog' inherits 'Dispose' from its 'Component' base type but does
not override it. The implementation in 'Component' looks as follows
(according to Reflector):
\\\
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If disposing Then
SyncLock Me
If _
( _
(Not Me.site Is Nothing) AndAlso _
(Not Me.site.Container Is Nothing) _
) _
Then
Me.site.Container.Remove(Me)
End If
If (Not Me.events Is Nothing) Then
Dim handler1 As EventHandler = _
DirectCast( _
Me.events.Item(Component.EventDisposed), _
EventHandler _
)
If (Not handler1 Is Nothing) Then
handler1.Invoke(Me, EventArgs.Empty)
End If
End If
End SyncLock
End If
End Sub
///
.... which does not prevent the dialog from working. It only disconnects it
from its container.
However, I recommend to call 'Dispose' here too because an implementation on
another operating system than Windows may add custom disposing code.