Solved

Form Disposal Question

Posted on 2003-11-14
5
185 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
Comment Utility
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
Comment Utility
Which event do I need to override to provide this behavior?
0
 
LVL 10

Accepted Solution

by:
smegghead earned 125 total points
Comment Utility
this.Hide();

rather than

this.Close();
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now