How to develop applications with multiple Forms?

M

Manfred Denzer

Hello developers!

I develop with C# and the .NET Compact Framework for Windows Mobile in
Microsoft Visual Studio 2005.
I'm very confused at the moment... I developed an application with
more than 30 forms (System.Windows.Forms.Form). Depending on what
button the user clicks, the next form will be loaded.

This is my structure: All forms inherit from a superclass, which
provides a full screen background image und some buttons needed on
every form. I develop a form-cache to save all forms when it is opened
the first time. If a form is needed a second time, the form opens very
quickly.

If I open a lot of forms, i get an OutOfMemoryException. So I look in
Windows Mobile in "Windows -> Settings -> System -> Memory". Oh, my
application needs over 25 MB RAM. Then, I clicked on "Running
Programs" and get frightened: The list is full with all my forms:
Form1, Form2, Form3, Form4, ...

Now, I think that I managed my forms wrong right from the start of
development, isn't it?
Is it better to have only ONE form and chance the controls on it?
Or is it ok to have multiple form? But it is not good to have a lot of
entries on "Running Programs", or?

Thank you very much for your help!
Manfred Denzer
 
C

Chris Tacke, eMVP

Running Programs simply lists the text in all top-level Forms. Set the text
of any given Form to an empty string and it won't show up.

The memory issue is becasue you have 30 Form is memory, along with all if
their referenced classes. You'll have to pitch data at some point. A
reasonable mechanism is to wrap calls in exception handlers and when you get
an OOM, pop some of the oldest forms from your cache. Another option is to
only cache frequently used Forms.

Using 1 form with lots of controls isn't going to buy you anything and would
be a nightmare to maintain.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
M

Manfred Denzer

Thank you very much for your detailed answer :)
I'm happy, that I not have to redevelop my application.
I will catch the OOM and remove Forms from my cache!
Greetings
Manfred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top