How to complete the process after closing the entire application in C # .NET?

I have a .NET 2005 desktop application (C #) that has a login form and an MDI form, which then have several subforms. All other forms open only in MDI form.

After the user logs in, I hide the login form and then show the MDI form, but when I close the MDI form, my application process does not end because the login form is still hidden. I want that when the user closes the MDI form, the whole application should close (essentially, the process should not be displayed in the task manager), because if every time the user closes and opens the application again and logs in, he will create some performance problems .

I am doing something like below:

//my login validation script, //after successful login this.Hide(); if (globalData.ObjMdiMain.IsDisposed) { globalData.ObjMdiMain = new mdiMain(); } globalData.ObjMdiMain.Show(); 

globalData is my static class where I create global objects that are required for the entire application. There I defined the ObjMdiMain object of my MDI form, and I refer to it here in the login form.

So, is there any method or function that will complete the entire process from the system, something like "Application.End ();" or something else?

Thanks!

+2
c # desktop-application visual-studio-2005
source share
7 answers

MySql.net connector error seems to be because I used the mysql.net DLL connector to connect to my mysql db. I also saw some others complain about it. See http://bugs.mysql.com/bug.php?id=36688

I used the MySQL.net connector DLL version 5.1, I just upgraded to 6.1 (the last) and worked fine, without any errors.

Download the latest DLL here: http://dev.mysql.com/downloads/connector/net/6.1.html

thanks

0
source share

I assume from your description (please correct me if I am wrong) that you have a login form as your startup form, for example:

  static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm()); } 

Do not do this. Instead, change it to the following:

  static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LoginForm frm = new LoginForm(); if(frm.ShowDialog() == DialogResult.Cancel) { return; } Application.Run(new MdiForm()); } 

In the code of the login form, do not call the MDI form at all, just confirm the username and password and let the login form exit. Then the Main method will call the MDI form.

Your application will then exit naturally when you close the MDI form.

+8
source share

It seems strange to me that you left the login window after the first login. Why not shut it down? Then you would not have your current problem: after a successful login, you will only have the main MDI window, which, when closed, exits the running Windows Forms application. Is there a reason why you hide the login window instead of closing it?

+1
source share

I assume you looked at Application.Exit ?

+1
source share

There is Application.Exit () that will send a Windows message to close all forms and exit the message loop.

0
source share

I don't like breaking it up on you, but ... Application.Exit() is what you ask for. If you really tried, you would find it. Although, I have to agree with peSHIr, why do you save the login form if this causes problems?

0
source share

Here is an example of closing the actual process, but this is a bad way to close the application:

 Environment.Exit(Code) 

you can set the code to 0. or another integer, this will mean that wath ww is the result of the application.

I advise you to first close the login form, and then close the application, this is the right way.

Good luck;)

0
source share

All Articles