473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dispose method problem

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("Kernel3 2")> _
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
Jul 19 '05 #1
1 3282
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

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
3
by: Vagabond Software | last post by:
Scenario: The end-user selects File-Save from my applications (WinForm) menu, specifies a filename, and waits waits for my app to write the contents of a dataset to an Excel workbook. The...
6
by: Teresa | last post by:
1) If I do want to keep an object alive throughout the live of an application, how can I ensure that the GC doesn't clean it up? 2a) How do I determine if an object is a managed or an unmanged...
14
by: Jonas | last post by:
Hi! I'm developing the middletiers of an ASP.NET application in VB.NET. I've got a business logic layer in which I would like to perform auditing to a database. Instead of making an auditing...
8
by: Howard Kaikow | last post by:
I've been trying to convert the following C# Dispose to VB .NET: protected override void Dispose(bool disposing) { if (excelThread != null) {
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
13
by: Grafix | last post by:
All - As we all know, Dispose method is reserved in C++ 8 and the expected syntax is to use ~MyClass(). In 1.1, we used to have following structure for Dispose class MyClass : IDisposable {...
5
by: Markus Stoeger | last post by:
Hi, I have a class similar to that: class MyClass : IDisposable { IDisposable obj1; IDisposable obj2; IDisposable obj3; MyClass() {
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.