Επιπρόσθετα:
Λόγω του οτι τo dispose γενικά ΔΕΝ είναι threadsafe, υπάρχει ένα common pattern που ακολουθείται για να κάνεις dispose ένα object. Σου παραθέτω τον κώδικα παρακάτω:
#Region " Constructors / Destructors "
'/// <summary>
'/// Default constructor.
'/// </summary>
Public Sub New()
'TODO: Insert Necessary object construction code
End Sub
'/// <summary>
'/// Standard Dispose Implementation Pattern, part II.
'/// Overridable and Overloaded Dispose procedure is called by both
'/// Dispose and Finalize Not Overridable procedures.
'/// </summary>
'/// <param name="p_bDisposing">
'/// If its value is True, then this procedure is called by User calling
'/// Dispose(). Else it is called by System calling Finalize().
'/// </param>
'/// <returns></returns>
Protected Overridable Overloads Sub Dispose(ByVal p_bDisposing As Boolean)
'User called Dispose(True)
If (p_bDisposing = True) Then
'TODO: Free other state (managed objects).
End If
'TODO: Free own state (unmanaged objects).
'Set large fields to null, etc.
End Sub
'/// <summary>
'/// Standard Dispose Implementation Pattern, part I.
'/// Not Overridable Dispose procedure just calls overloaded Dispose(True).
'/// </summary>
Public Overloads Sub Dispose() Implements System.IDisposable.Dispose
'Call common overloaded and overridable disposing procedure
'to perform all necessary finalization actions.
Dispose(True)
'Remove this object from the Finalization Queue,
'because Dispose procedure has already been called.
GC.SuppressFinalize(Me)
End Sub
'/// <summary>
'/// Standard Dispose Implementation Pattern, part III.
'/// Not Overridable Finalize procedure just calls Dispose(False).
'/// </summary>
Protected Overrides Sub Finalize()
'Simply call Dispose(False), because user has not already
'called Dispose () to perform object finalization process.
Dispose(False)
End Sub
#End Region
Σωτήρης Φιλιππίδης
DotSee Web Services