Two ways to exit an application

M

Manfred Denzer

I develop with C# and the .NET Compact Framework for Windows Mobile in
Microsoft Visual Studio 2005. In Windows Mobile, there are two ways to
exit an application:
a) the application is terminated completely
b) the application is still in RAM and if you start it a second time,
you restore the application

How can a implement this to ways with C#? My application is a
System.Windows.Forms.Form.
For a), I use "Application.Exit();", is this correct?
What is with b)?

Thank you very much for your help!
Manfred Denzer
 
M

Manfred Denzer

Thanks for your reply!

"form.Hide();" hides the application, but how can I make it visible
again?
If I try to start my application again in the File-Explorer, nothing
happens.
Maybe Windows tries to start the application a second times instead of
restoring the running application.

Manfred Denzer
 
R

Robert Scott

Manfred Denzer said:
Thanks for your reply!

"form.Hide();" hides the application, but how can I make it visible
again?
If I try to start my application again in the File-Explorer, nothing
happens.
Maybe Windows tries to start the application a second times instead of
restoring the running application.

Yes, that is what happens. So then the question is, what does your application
do when a new instance of it is started up? What you could do is detect that
the first instance is already running (there are various ways to do that) and if
it is, bring it to the foreground and exit that second instance.


Robert Scott
Ypsilanti, Michigan
 
M

Manfred Denzer

Yes, that is what happens.  So then the question is, what does  your application
do when a new instance of it is started up?  What you could do is detect that
the first instance is already running (there are various ways to do that)and if
it is, bring it to the foreground and exit that second instance.

Robert Scott
Ypsilanti, Michigan

Thank you for your answer :)
Here is my code how I start my application.
Can you say me how I could detect that the first instance is already
running and bring it to the foreground again?


private MyForm form;
private doExitApplication = false;

static void Main() {
form = new MyForm();
startForm();
}

private static void startForm() {
try {
form.Visible = true;
do {
Application.DoEvents();
} while (!doExitApplication);
} catch (OutOfMemoryException) {
// de-allocate resources...
startForm();
} catch (Exception e) {
// inform user and exit application
doExitApplication = true;
Application.Exit();
}
}
 
C

Chris Tacke, eMVP

What!? Why would you use such a pattern? Application.Run is designed to
set up an application message pump properly - all you're doing is eating up
major processor bandwidth and battery life. There's no point is discussing
how to activate a running instance. You need to fix the fundamentals first.
Once you do that, set your app's main Form's "ShowMinimize" to true and it
will probably do everything you want.


--

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



Yes, that is what happens. So then the question is, what does your
application
do when a new instance of it is started up? What you could do is detect
that
the first instance is already running (there are various ways to do that)
and if
it is, bring it to the foreground and exit that second instance.

Robert Scott
Ypsilanti, Michigan

Thank you for your answer :)
Here is my code how I start my application.
Can you say me how I could detect that the first instance is already
running and bring it to the foreground again?


private MyForm form;
private doExitApplication = false;

static void Main() {
form = new MyForm();
startForm();
}

private static void startForm() {
try {
form.Visible = true;
do {
Application.DoEvents();
} while (!doExitApplication);
} catch (OutOfMemoryException) {
// de-allocate resources...
startForm();
} catch (Exception e) {
// inform user and exit application
doExitApplication = true;
Application.Exit();
}
}
 
M

Manfred Denzer

Oops, I'm new with development of mobile applications. I'm very
thankful with your hints! :)
Here you can find my new code. Is it ok to call "startForm()" again in
the OutOfMemoryException?

I looked to the properties of Form, but don't find the property
"ShowMinimize". Where can I find it?


private MyForm form;

static void Main() {
form = new MyForm();
startForm();
}

private static void startForm() {
try {
Application.Run(form);
} catch (OutOfMemoryException) {
// de-allocate resources...
startForm();
} catch (Exception e) {
// inform user and exit application
Application.Exit();
}
}
 
M

Manfred Denzer

If someone have an idea for me, I would be very happy :)

- Is it ok to call "startForm()" again in the OutOfMemoryException?
- Where can I find the properties "ShowMinimize" and how do I bring
the application back to the foreground?

Thank you very much!
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