1

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?

4
  • 1
    possible duplicate of: stackoverflow.com/questions/5706497/… Commented Jul 5, 2017 at 1: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? Commented Jul 5, 2017 at 1:38
  • That link won't work because it uses the Application.Executable path. Try reading my question before calling it a duplicate Qiqo Commented Jul 5, 2017 at 1:40
  • You could just restart all your variables in app and just clear screen. It's a bit sketchy but it should work. Commented Jul 5, 2017 at 1:40

2 Answers 2

1

Found it:

var info = new System.Diagnostics.ProcessStartInfo(Environment.GetCommandLineArgs()[0]); System.Diagnostics.Process.Start(info); 
Sign up to request clarification or add additional context in comments.

1 Comment

Works for me in VB.NET! But needs an "END" instruction on next line.
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.

2 Comments

This does not work for me. It won't even import System.Windows.Forms.
You 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.