C# method to restart the application
-
Hi!! I wanna code a method that can restart the application without any user involvment.. I mean when an error is encountered, the method can be used to restart the application.. Plz help me out...
You can use following code to do so
// Shut down the current app instance.
Application.Exit();// Restart the app passing "/restart [processId]" as cmd line args
Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id);HTH
Jinal Desai - LIVE Experience is mother of sage....
-
You can use following code to do so
// Shut down the current app instance.
Application.Exit();// Restart the app passing "/restart [processId]" as cmd line args
Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id);HTH
Jinal Desai - LIVE Experience is mother of sage....
-
You can use following code to do so
// Shut down the current app instance.
Application.Exit();// Restart the app passing "/restart [processId]" as cmd line args
Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id);HTH
Jinal Desai - LIVE Experience is mother of sage....
-
Ok its working.... Thanks for this... But will it work on a Console Application too... I cudnt find this Application... How shud i integrate it in my code?? Its not exiting but ya its opening another instance... How shud i get it working...
Try following code
Close();
System.Diagnostics.Process.Start(Application.ExecutablePath);or you can also do following Add using System.Windows.Forms; to the top and call
Application.Restart();
You may need to add the reference: "System.Windows.Forms.dll" to your project.
Jinal Desai - LIVE Experience is mother of sage....
-
Try following code
Close();
System.Diagnostics.Process.Start(Application.ExecutablePath);or you can also do following Add using System.Windows.Forms; to the top and call
Application.Restart();
You may need to add the reference: "System.Windows.Forms.dll" to your project.
Jinal Desai - LIVE Experience is mother of sage....
Close() cant be used... m using Visual Studio 2010 n its not allowing... I mean its giving error... And Application.Restart() is working fine but it aint closing the previous instance... How shud i close the console window forcibly.. Should i use Process.Kill()??
-
Close() cant be used... m using Visual Studio 2010 n its not allowing... I mean its giving error... And Application.Restart() is working fine but it aint closing the previous instance... How shud i close the console window forcibly.. Should i use Process.Kill()??
-
Ya you can also go for kill method to kill your process...
Jinal Desai - LIVE Experience is mother of sage....
To kill the application i've used Process.GetCurrentProcess().Kill(); To restart { Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id); Process.GetCurrentProcess().Kill(); } Thanks for the help... If u can find anyother more appropriate way plz let me know... Ayan
-
Hi!! I wanna code a method that can restart the application without any user involvment.. I mean when an error is encountered, the method can be used to restart the application.. Plz help me out...
Application.Restart();
stops the current process and starts a new identical one. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Application.Restart();
stops the current process and starts a new identical one. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
This one wont work in console application... this will open a new instance of the application but cant close the current instance...
How was Luc supposed to know it was a Console application? You didn't volunteer this info up front.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
How was Luc supposed to know it was a Console application? You didn't volunteer this info up front.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads