473,395 Members | 1,578 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,395 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 3285
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.