From: Manfred Denzer on
Hello!

I develop with C# and the .NET Compact Framework for Windows Mobile in
Microsoft Visual Studio 2005 and I have some very basic questions:

### -> 1. How do I start an application and react to an
OutOfMemoryException?
This is my code at the moment:

static void Main() {
form = new MyForm();
startForm();
}
private static void startForm() {
try {
Application.Run(form);
} catch (OutOfMemoryException) {
// de-allocate resources...
startForm();
}
}

This code doesn't work. If an OutOfMemoryException is thrown, the
application exit.


### -> 2. How can I close and restart an application?
If my application is running and I press the "Home" button of my PDA
and work in other application, I can go back to my application with
starting it a second time. This works!
But how can I "minimize" my application manually? I want to add a
button "Back to Windows" in my application.


### -> 3. I have only a process - how to make an application?
There is a Task Manager in Windows Mobile 6.1. If I start my
application, go back to windows and start the Task Manager, there's no
application in the list. If I switch to "Show -> Processes", I see the
"myApp.exe". I want to have my application is in the application list
and not only in the process list.


Thank you very much for your help!
Manfred
From: Chris Tacke, eMVP on
> ####### 1 #######
> Hmmm, the code doesn't do what I want yet. I see the MessageBox, but
> my application exits directly and the form doesn't stay open:

This is expected behavior.

If you look at the args that come in to the exception handler, you'll see
the runtime is terminating. If your app is terminating due to OOM, there
are two problems with what you're trying:

1. Why would you expect that there will be enough memory after you catch the
exception to run? Catching an exception doesn't magically free memory.
2. You need to be handling the exception *where it occurs* not just in some
broad location in your app.


--

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