T
Teeravee Sirinapasawasdee
Here is code from MSDN-Library April 2003 which I tried to implement to my class but there was some error that I don't know how to solve it. In Privete Overloads Sub Dispose(ByVal disposing Boolean), the code call component.Dispose() method but the VS said that 'System.ComponentModel.Component.Protected Overrridable Sub Dispose(disposing As Boolean)' is not accessible in this context because it is 'Protected'. I don't know this code is from .NET Framework 1.0 and not yet update for 1.1 or not. If anyone know how can I correct this error, please let me know.
Thank you,
Teeravee Sirinapasawasdee
Imports System
Imports System.ComponentModel
Public Class DisposeExample
Public Class MyResource
Implements IDisposable
Private handle As IntPtr
Private component As component
Private disposed As Boolean = False
Public Sub New(ByVal handle As IntPtr)
Me.handle = handle
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Private Overloads Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposed Then
If disposing Then
component.Dispose() <-- There was error here!
End If
CloseHandle(handle)
handle = IntPtr.Zero
End If
disposed = True
End Sub
<System.Runtime.InteropServices.DllImport("Kernel32")> _
Private Shared Function CloseHandle(ByVal handle As IntPtr) As [Boolean]
End Function
Protected Overrides Sub Finalize()
Dispose(False)
MyBase.Finalize()
End Sub
End Class
End Class
Thank you,
Teeravee Sirinapasawasdee
Imports System
Imports System.ComponentModel
Public Class DisposeExample
Public Class MyResource
Implements IDisposable
Private handle As IntPtr
Private component As component
Private disposed As Boolean = False
Public Sub New(ByVal handle As IntPtr)
Me.handle = handle
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Private Overloads Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposed Then
If disposing Then
component.Dispose() <-- There was error here!
End If
CloseHandle(handle)
handle = IntPtr.Zero
End If
disposed = True
End Sub
<System.Runtime.InteropServices.DllImport("Kernel32")> _
Private Shared Function CloseHandle(ByVal handle As IntPtr) As [Boolean]
End Function
Protected Overrides Sub Finalize()
Dispose(False)
MyBase.Finalize()
End Sub
End Class
End Class