473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1736
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Vaughan | last post by:
I have a class that is sometimes called from the command line and sometimes from another class. When the user clicks "Quit" on the panel it opens, if it is running from the command line, it...
5
by: Tim Clacy | last post by:
When exiting function scope, which occurs first: a) destruction of local objects b) copy of value for return From disassembly of a debug target, it looks like the return value is copied before...
22
by: L. Westmeier | last post by:
Is there a way to have to exiting point in a void function? I don't want to exit the program but just this function. Any answers appreciated. L. Westmeier
8
by: Andrew Warren | last post by:
I'm trying to exit a Windows Forms application while in the form's constructor (after InitializeComponent() has been called) and am finding that calling Application.Exit () still leaves the form...
3
by: Bonj | last post by:
When trying to debug an ASP.NET project by placing a breakpoint in one of the functions in the codebehind, VS correctly stops at the breakpoint, and I can step through. But soon after, the process...
5
by: Tim Werth | last post by:
I have a .NET console application that is kicked off by a .NET Windows service. They communicate via .NET Remoting, although there isn't much communication between the two while the console app is...
1
by: kuhrty | last post by:
Hi, I am creating a multi-winform project. Everything has been working fine, except after I perform an update to the database and decide to Exit the winform after the update operation is...
6
by: Ant | last post by:
Hi all, I'm putting together a simple help module for my applications, using html files stored in the application directory somewhere. Basically it sets up a basic web server, and then uses the...
6
by: John (Z R) L | last post by:
Hi all, I am very new to programming, and I chose to study the Python language before C++. I am currently using the Wikibooks "Non-Programmer's Tutorial for Python", and am up to the section "Who...
5
by: care02 | last post by:
Hi! I have the following problem: I have written a short Python server that creates an indefinite simulation thread that I want to kill when quitting (Ctrl-C) from Python. Googling around has...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.