473,396 Members | 1,924 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,396 software developers and data experts.

Dispose member already defined?

Ole
I have created an user control (that inherits UserControl) in which I have
defined an override on the Dispose member like this:

protected override void Dispose( bool disposing )
{
try
{
blackPen.Dispose();
redPen.Dispose();
bluePen.Dispose();
}
catch
{ }
}

But the compiler complains with the error message:
"The Control" already defines a member called 'Dispose' with the same
parameter

Any clue what could be wrong?

Thanks
Ole
Oct 25 '07 #1
2 3284
Ole,

Well, the compiler error is pretty explicit. Did you look in the
designer generated code? My guess is that is where you will find the method
that the designer created.

If you are storing these pens, and want to get rid of them when
disposing, then I would modify that method to dispose of your pens.

If modifying designer-generated code doesn't sound like a great idea to
you, you could create a class which derives from Component, and then add
that to your form. Then, on that component, you would have an Add method
which would take an IDisposable reference, and in that component's dispose
method, you would cycle through and call Dispose on whatever was added
(which you have to keep a list of internally, of course).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ole" <ol*@blabla.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have created an user control (that inherits UserControl) in which I have
defined an override on the Dispose member like this:

protected override void Dispose( bool disposing )
{
try
{
blackPen.Dispose();
redPen.Dispose();
bluePen.Dispose();
}
catch
{ }
}

But the compiler complains with the error message:
"The Control" already defines a member called 'Dispose' with the same
parameter

Any clue what could be wrong?

Thanks
Ole

Oct 25 '07 #2
Ole
Hi Nicholas,

You're absolutely right - why didn't I figure that out - well thanks for
your help!

BR
Ole
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:u5**************@TK2MSFTNGP02.phx.gbl...
Ole,

Well, the compiler error is pretty explicit. Did you look in the
designer generated code? My guess is that is where you will find the
method that the designer created.

If you are storing these pens, and want to get rid of them when
disposing, then I would modify that method to dispose of your pens.

If modifying designer-generated code doesn't sound like a great idea to
you, you could create a class which derives from Component, and then add
that to your form. Then, on that component, you would have an Add method
which would take an IDisposable reference, and in that component's dispose
method, you would cycle through and call Dispose on whatever was added
(which you have to keep a list of internally, of course).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ole" <ol*@blabla.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>I have created an user control (that inherits UserControl) in which I have
defined an override on the Dispose member like this:

protected override void Dispose( bool disposing )
{
try
{
blackPen.Dispose();
redPen.Dispose();
bluePen.Dispose();
}
catch
{ }
}

But the compiler complains with the error message:
"The Control" already defines a member called 'Dispose' with the same
parameter

Any clue what could be wrong?

Thanks
Ole


Oct 25 '07 #3

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

Similar topics

2
by: Simon | last post by:
Hi. I don't have a problem per se, I was just wondering if anyone can offer some opinions about the best way to go about creating and disposing of a Singleton class. I have a class (handling...
3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
4
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or...
4
by: Andreas Huber | last post by:
Hi there Is there a reason why .NET framework base classes implementing IDisposable (like e.g. System.ComponentModel.Component) do not prevent multiple calls to the protected virtual void...
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...
8
by: Gawelek | last post by:
When I write this code namespace WindowsApplication1 { public class Form1 : System.Windows.Forms.Form { (...) /// <summary> /// Clean up any resources being used. /// </summary>
6
by: Bob | last post by:
When implementing the Dispose() method, I understand that it's supposed to do what Finalize() does so that's why it should call GC.SuppressFinalize(). However, it's not clear to me what happens the...
13
by: Dave | last post by:
Could someone explain to me when it is appropriate to call the Dispose() method that is contained in most .Net Framework Objects. The MSDN says that Dispose: Releases all resources used by the...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.