Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have several classes that I need to implement a dispose method on. Problem being is when you dispose of the class it is still callable. Ie. I have esentially stopped everything that needs to be stopped but the hook still exist. I thow an exception if it has been disposed but how/when is the final disposition handled?
  • *Experts*
Posted

Have you read up on what Dispose is used for? If you're worried about being able to use an object once it's "disposed" then what you want is to set it to Nothing. Dispose is used when you need to free resources that must be freed immediately such as file handles, window handles, device contexts, etc.

 

Are you having problems with a program not shutting down after the last form is closed or something similar? To me a "hook" is something specific - it's when you are hooking into a window message handler or something "advanced".

 

Some clarification, please :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Sorry for the poor description and terminology.

 

I have a class object that use periodically. I want to shut it down (stop/abort a thread that is used, dump some data to a file, etc.) and free up the resources used by the class. Once 'disposed' I do not need/want to do anything with the class without having to declare a new one.

 

The document I referenced before indicates that the methods etc. are still available and that they should throw an exception (Which indicates to me that the class is not truly gone (free).

 

What I have done so far in the dispose function is take care of cleanup (as mentioned before). At the end I call GC.cleanup (to get rid of variables that are out of scope). But - like I said the document indicates that the class methods and class scoped variables are still active.

 

Would I be correct in assuming that if I call dispose, set the class declaration variable to nothing and call GC.cleanup that it would no longer be available and that all resources would be free?

Posted

think I found my answer :)

 

call some routine to do whatever cleanup I need and then set the thing to Nothing. This should set the pointer to 0 and on GC.cleanup it should reclaim - correct?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...