PC Review


Reply
Thread Tools Rate Thread

Dispose method problem

 
 
Teeravee Sirinapasawasdee
Guest
Posts: n/a
 
      31st Jul 2003
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
 
Reply With Quote
 
 
 
 
Ganeshram
Guest
Posts: n/a
 
      1st Aug 2003
Hi Sirinapasawasdee,
U have not initialized the Component object,
Plz intialize the object in the constructor as
Public Sub New(ByVal handle As IntPtr)
Me.handle = handle
component = New Component()
End Sub
and try running the program.Actually the object is being
tried to use with out initializing it
Bye
>-----Original Message-----
>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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
about the Dispose method Tony Johansson Microsoft C# .NET 0 11th Nov 2010 09:57 AM
Dispose Method Dave Microsoft Dot NET 13 2nd May 2006 12:27 AM
If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws "The specified network name is no longe Daniel Microsoft C# .NET 1 8th Sep 2005 09:44 AM
If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws "The specified network name is no longe Daniel Microsoft Dot NET 3 8th Sep 2005 07:54 AM
If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws "The specified network name is no longe Daniel Microsoft Dot NET Framework 1 8th Sep 2005 04:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:55 PM.