469,913 Members | 2,648 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Exiting from an app

pnp
Hi all,
I'm working on a win app that uses a logon form to verify the user that
logs in the program and then hides the first form and displays an MDI
form where the user does his work. The app is STA.
The problem is that I wan't to be able to close the app from wherever in
my app (no matter how deep in the code) and make sure that all the
resources are being freed after exiting the app. Any ideas?
Is there a way to re-open the app programmaticaly after it has been
closed so that another user can login?

Thanks in advance,
Peter.
Nov 16 '05 #1
2 1580
Peter,

You could always call the static Exit method on the Application class.
This should send a shutdown message to your app, which would then close.

However, to get the kind of behavior that you want, I think that you
need to go through a loop, like so:

// In main section.
// Continue?
bool cont = true;

while (cont)
{
// Create login form and show it.
LoginForm loginForm = new LoginForm();

// Show in a message loop.
Application.Run(loginForm);

// Check a property to see if the form actually was logged into
correctly, or not cancelled.
// Make sure to name this property something else.
cont = loginForm.ShouldContinue;

// If continuing, then show the main form.
if (cont)
{
// Show the MDI form.
ClientForm clientForm = new ClientForm();

// Show.
Application.Run(clientForm);
}
}

This should give you the behavior that you want, and calling
Application.Exit anywhere from within your main client code should cause you
to exit (although I don't think that is a good idea, personally).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"pnp" <pnp.@.softlab.ntua.gr> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I'm working on a win app that uses a logon form to verify the user that
logs in the program and then hides the first form and displays an MDI form
where the user does his work. The app is STA.
The problem is that I wan't to be able to close the app from wherever in
my app (no matter how deep in the code) and make sure that all the
resources are being freed after exiting the app. Any ideas?
Is there a way to re-open the app programmaticaly after it has been closed
so that another user can login?

Thanks in advance,
Peter.

Nov 16 '05 #2
pnp
Nicholas Paldino [.NET/C# MVP] wrote:
Peter,

You could always call the static Exit method on the Application class.
This should send a shutdown message to your app, which would then close.

However, to get the kind of behavior that you want, I think that you
need to go through a loop, like so:

// In main section.
// Continue?
bool cont = true;

while (cont)
{
// Create login form and show it.
LoginForm loginForm = new LoginForm();

// Show in a message loop.
Application.Run(loginForm);

// Check a property to see if the form actually was logged into
correctly, or not cancelled.
// Make sure to name this property something else.
cont = loginForm.ShouldContinue;

// If continuing, then show the main form.
if (cont)
{
// Show the MDI form.
ClientForm clientForm = new ClientForm();

// Show.
Application.Run(clientForm);
}
}

This should give you the behavior that you want, and calling
Application.Exit anywhere from within your main client code should cause you
to exit (although I don't think that is a good idea, personally).

Hope this helps.


Thank you very much for your answer. It was a big help to me!
Peter
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hal Vaughan | last post: by
5 posts views Thread by Tim Clacy | last post: by
22 posts views Thread by L. Westmeier | last post: by
8 posts views Thread by Andrew Warren | last post: by
3 posts views Thread by Bonj | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.