473,664 Members | 3,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1753
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.Shoul dContinue;

// 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.Exi t 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.co m
"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:es******** ******@TK2MSFTN GP10.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.Shoul dContinue;

// 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.Exi t 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
3035
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 quits. The problem is that I need a way to terminate the class and the object without using quit, so it doesn't kill other classes. The QUIT button calls an actionListener, so if I have "return" in the listener, it closes the window, but the class is...
5
1620
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 local objects are destroyed. Is this standard behaviour? Can the same behaviour be expected for any optimisation level? As an example, in the function 'int A::fn()' here, is 'b' destroyed before 'i' is copied or vice-versa?:
22
5975
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
2589
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 displayed and running. Trying to force the form to close with this.Close() does not work either. Any suggestions? Thanks.
3
1509
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 stops dead and can't be stepped through anymore (even though there is no error) - I'm guessing that the aspnet_wp.exe is detecting that if it's inactive for a period of n seconds or so, then it exits until it gets another request. Is there...
5
3852
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 running. There can be, and are typically, several instances of the console app running at the same time communicating back to the service. The console app creates a delegate to do some work while the main thread waits on a ManualResetEvent to...
1
1900
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 complete. I have error handling in my code but not on the dispose method. I call the dispose method exiting the application using the code below but results in this error message "An unhandled exception of type 'System.NullReferenceException'
6
2494
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 webbrowser module to display it in the users browser. I have it set up to call sys.exit(0) if the url quit.html is called, but for some reason (on Windows XP via the cmd.exe shell) python won't let me have the console back. I get the System Exit...
6
5243
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 goes there"? http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Who_Goes_There%3F But after clicking "run module" for " a = 1
5
10578
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 not given me any hints on how to cleanly kill running threads before exiting. Any help is appreciated! Carl
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.