Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Form Disposal Question

Posted on 2003-11-14
5
188 Views
Last Modified: 2010-04-16
I have a question about how and when an instance of System.Windows.Form get's disposed.  Here is the scenario:

I created a form, showd it and then put a reference to said form in a hashtable.  I then closed the form.  When I later attempted to access the object through the hashtable I got an exception saying it had been disposed.  Shouldn't the reference in the hashtable be sufficient to keep this form from being disposed?  If not is there anyway to prevent the form from being disposed on closure?  Finally if I can't prevent the disposal on closure is there any way to determin if a reference refers to an object which has been previously disposed?
0
Comment
Question by:derekl
  • 2
5 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 9749220
What you can do is 'hide' the form rather than close it, this will prevent it from being disposed of.

Smg.
0
 

Author Comment

by:derekl
ID: 9749532
Which event do I need to override to provide this behavior?
0
 
LVL 10

Accepted Solution

by:
smegghead earned 125 total points
ID: 9749623
this.Hide();

rather than

this.Close();
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question