Hereâs a neat little thing about Visual Studio 2005 IDE for Visual
Basic.Net. When you implement the IDisposable interface, the
following code is automatically created for you. Update: As Blair mentioned in the comments, for C# IDE you can right click on the IDisposable term and pick if you want to explicitly
or implictly fill in the stubs for the interface.
VB.Net 2.0 in 2005 IDE IDisposable implementation
Public Class MyClass Implements IDisposable
Private disposed As Boolean = False
' IDisposable Private Overloads Sub Dispose(ByVal disposing As Boolean) If Not Me.disposed Then If disposing Then ' TODO: put code to dispose managed resources End If
' TODO: put code to free unmanaged resources here End If Me.disposed = True End Sub
#Region " IDisposable Support " ' This code added by Visual Basic to correctly implement the disposable pattern. Public Overloads Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. Dispose(True) GC.SuppressFinalize(Me) End Sub
Protected Overrides Sub Finalize() ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. Dispose(False) MyBase.Finalize() End Sub #End Region