I need an advice about Dispose()

S

Sam Sungshik Kong

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top