Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to close the windows application form and then again open the Login Screen. For the first time the application gets closed and open the login screen and the second time the application didn't get close....how can I close the current application and open the login page everytime...Please give some idea ji..

What I have tried:

Application.Exit();
Login L = new Login();
L.Show();
Posted
Updated 3-Feb-21 2:55am
v2
Comments
The Other John Ingram 3-Feb-21 8:56am    
try Application.End

1 solution

You can do it like this:
var exeName = Process.GetCurrentProcess().MainModule.FileName;
ProcessStartInfo startInfo = new ProcessStartInfo(exeName);
startInfo.Verb = "runas";
startInfo.Arguments = "restart";
Process.Start(startInfo);
Application.Exit();

The advantage of passing the "restart" parameter is that you can use that as a flag in Program.cs to start another form.
 
Share this answer
 
Comments
Member 15028582 3-Feb-21 23:23pm    
Thanks ji

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900