473,402 Members | 2,061 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,402 software developers and data experts.

I need an advice about Dispose()

Hello!

I am creating a user control.
It draws something in OnPaint method every 0.5 second.
Instead of creating a Pen object and disposing it every time in the method,
I create a Pen object in the constructor and want to dispose it.

My question is what's the best way to dispose it?
Do I have to follow the "Implementing a Dispose Method" guide of MSDN?
It seems to be a lot of additional code.

TIA.
Sam
Nov 16 '05 #1
1 1087
Sam,

Yes, that's pretty much what you have to do for any class that holds
onto a resource which requires Dispose called on it. It's not that much
extra code, really, it just seems like a lot. It's only about 30 lines, and
you can cut and paste it easily.

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

"Sam Sungshik Kong" <ss*@chol.nospam.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hello!

I am creating a user control.
It draws something in OnPaint method every 0.5 second.
Instead of creating a Pen object and disposing it every time in the
method, I create a Pen object in the constructor and want to dispose it.

My question is what's the best way to dispose it?
Do I have to follow the "Implementing a Dispose Method" guide of MSDN?
It seems to be a lot of additional code.

TIA.
Sam

Nov 16 '05 #2

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

Similar topics

1
by: Chien Lau | last post by:
Hi, Consider the following code where 'CM' is a reference to a ContextMenu: MenuItem menuItems=new MenuItem{ new MenuItem("Add",new EventHandler(MI_Click)), new MenuItem("Remove",new...
4
by: Johannes Hansen | last post by:
What are the best practice on handling an exception caused by a Dispose method when its called from inside a loop? Wrap the entire loop in a try-catch or do the try-catch on each iteration to get...
14
by: Nick Z. | last post by:
I have a file that I want to read a UTF-16 unicode string from. What is the easiest way to accomplish that? Thanks in advance, Nick Z.
2
by: G.Ashok | last post by:
Hi, Is it necessary to dispose the objects created in procedure be disposed manually? Why can't we just rely on the GC to do the job? For example: I have this: Sub SomeSub1()
13
by: Boni | last post by:
I use 3-d party component. In this component I must pass a reference to my object. The problem is that this component has an ugly bug.When this component is disposed, it incorrectly don't delete...
2
by: Piotrekk | last post by:
Hi. I have written client and server app. that sends files. Client application doesn't use threads, but server does. I would like to show you part of my code ( thread) and ask why, when i close...
2
by: Robert Vasquez | last post by:
I have three classes. One (Class ObjectC) and two other classes (Class1 and Class2) that will hold instances of the ObjectC class. I would like to transfer an instance of OjectC from Class1 into...
3
by: shapper | last post by:
Hello, I created a simple class as follows: Public Class HelloWorld Public Function SayMessage() As String Return "Hello World!" End Function
2
by: not_a_commie | last post by:
Are there any tools available to track down IDisposable objects that don't have a call to Dispose? I'm thinking this can be done with static code analysis. If the object is created inside a method,...
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
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.