We help IT Professionals succeed at work.
Get Started

Windows forms usage (specifically targetting .NET Compact)

Last Modified: 2012-08-13

Hoping to clarify a few things, I am seeking advice rather than a solution.

I have produced an application for a Windows CE4 device and have some queries regarding Windows forms and some correct/incorrect assumptions I may have.

1) What is the "best" way (in terms of performance) of closing and opening a new form? I have a menu system, clicking on an option opens a new form. At present I am achieving this with:

dim x as new NameOFForm

On close, I also run a routine which sets all objects to nothing.  Should I be disposing of the form as well (as I understand it, calling close also calls dispose)?

When manually calling dispose(), on some occassions, I get an "Object Disposed exception" which presumably means I havent set everything to nothing?

This method also seems to (overtime) consume some memory. Running a thread watch also shows that the old forms still exist though they may be set to nothing - are they consuming resources or just empty structures awaiting GC?

2) Is it bad practice to call dispose on an object/form? I've heard conflicting reports on whether this is a good idea. Should I leave it upto garbage collection?

3) Sometimes when closing a form (very occassionally) I receive a native exception error - any ideas (in general) what might cause a native exception? I understand this may be as a result of using unmanaged code (GetPowerStatusEX) or is to do with form disposal?

4) If I close/dispose of a form, since child controls exist on this form - are they disposed of automatically as well or do I manually have to set them all to nothing? I believe they still exist, since closing a form causes an object disposed exception when a timer on the form ticks.

Thanks for any help.

Watch Question
Software Architect
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE