This question has been asked before but I cannot find an answer that works. I need to get a C# CONSOLE program to restart periodically. Each of the other answers use the Application.Restart or Application.ExecutablePath which are not supported in console apps. What code or reference can I use to restart a C# application?
Asked
Active
Viewed 8,693 times
1
-
1possible duplicate of: https://stackoverflow.com/questions/5706497/how-restart-the-console-app#5706564 – Qiqo Jul 05 '17 at 01:33
-
"*I cannot find an answer that works*", you would need to be more specific, otherwise your question will be marked as duplicate. How exactly did others' answers not help you? Is "**Launch a second .exe that ends the console program, starts a new instance, and ends itself?**" not what you're looking for? – Keyur PATEL Jul 05 '17 at 01:38
-
That link won't work because it uses the Application.Executable path. Try reading my question before calling it a duplicate Qiqo – David Richards Jul 05 '17 at 01:40
-
You could just restart all your variables in app and just clear screen. It's a bit sketchy but it should work. – someRandomSerbianGuy Jul 05 '17 at 01:40
2 Answers
1
Found it:
var info = new System.Diagnostics.ProcessStartInfo(Environment.GetCommandLineArgs()[0]);
System.Diagnostics.Process.Start(info);

David Richards
- 21
- 1
- 3
-
Works for me in VB.NET! But needs an "END" instruction on next line. – Doug Null Nov 18 '21 at 00:45
0
This command will work:
System.Windows.Forms.Application.Restart();
But you need to make sure you added and referred to correctly assembly. It's System.Windows.Forms in Assembly.

Thang Pham
- 611
- 5
- 12
-
This does not work for me. It won't even import System.Windows.Forms. – David Richards Jul 05 '17 at 01:46
-
1You just right click on "References", select "Add Reference...", in Assemblies, Framework, you find for System.Windows.Forms., select it then click OK. Copy the above line to your console application then it will work. I've just double checked. – Thang Pham Jul 05 '17 at 01:47