Start and initialize an application correct in Windows Mobile

M

Manfred Denzer

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
 
M

Manfred Denzer

Hi Christian,

thank you very much for your help! Your blog is great, I use your
"Transparent Controls in .NETCF" some month ago... oh, I found a
message from myself in your blog ;-)
http://christian-helle.blogspot.com/2008/01/transparent-controls-in-netcf.html#c4329755486343562236

####### 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:

static void Main() {
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
Application.Run(form);
}
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e) {
MessageBox.Show("Hello World!");
// do I need a second call "Application.Run(form);" here?
}

####### 2 #######
Great! It works! I can minimize my application :)
But if a reopen my application, I have a little refresh problem with
some of my buttons. Is there any event that I can use, if the
application opens?

####### 3 #######
Great! The application is in the task list now :)
"this.Text" was missing, I only use "this.Name" before.

Greetings
Manfred
 
C

Chris Tacke, eMVP

####### 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
 

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