Re: Object destruction VB.NET 2005
- From: "Sid Price" <sid@xxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 16:20:36 -0700
Hi Scott,
I tried implementing IDisposable in my class and when I close the
application the Dispose method is not being called. If I break using the
debugger the blocked thread is still blocked. Since the object running that
thread is a member of the object I need to dispose will "Dispose" ever get
called before the thread exits?
Sid.
"Scott M." <smar@xxxxxxxxxxxxx> wrote in message
news:ejcDoLpbIHA.5400@xxxxxxxxxxxxxxxxxxxxxxx
You should implement the IDisposable interface with a proper
Dispose/Finalize pattern. As a rule, you don't actually put your clean up
code in the Finalize method, you put it into a Dispose method. When the
user of the class instantiates it, they can/should use a "Using" block, so
that the object will call Dispose automatically when the end of the Using
block is hit. Or the class user could manually call Dispose when they are
done using it. And, if all else fails, the Finalze method will call
Dispose if/when the object is collected.
http://msdn2.microsoft.com/en-us/library/b1yfkh5e(vs.71).aspx
-Scott
"Sid Price" <sid@xxxxxxxxxxx> wrote in message
news:uwMVsEpbIHA.4936@xxxxxxxxxxxxxxxxxxxxxxx
Hi everyone,
I have a class that creates a thread for some I/O that blocks in the
absence of any activity. I need to be able to shut down that thread when
the application using the class closes. I tried putting my code to close
the thread in the Finalize call of the object but when the app closes
Finalize is not called. A simple solution is to create a public "Close"
method for the object however I would have hoped for an automatic method
since the class in question is to be a reusable class library and it
seems better practice for it to clean up when the instances are destroyed
without code needing to be called by the application using the library.
Any suggestions please?
Sid.
.
- Follow-Ups:
- Re: Object destruction VB.NET 2005
- From: Jack Jackson
- Re: Object destruction VB.NET 2005
- References:
- Object destruction VB.NET 2005
- From: Sid Price
- Re: Object destruction VB.NET 2005
- From: Scott M.
- Object destruction VB.NET 2005
- Prev by Date: Re: CPU and Memory Information
- Next by Date: Re: Multi-Threading
- Previous by thread: Re: Object destruction VB.NET 2005
- Next by thread: Re: Object destruction VB.NET 2005
- Index(es):
Relevant Pages
|