David Richards
David Richards

Reputation: 21

C# Restart Console Application

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?

Upvotes: 1

Views: 9210

Answers (2)

David Richards
David Richards

Reputation: 21

Found it:

var info = new System.Diagnostics.ProcessStartInfo(Environment.GetCommandLineArgs()[0]);
System.Diagnostics.Process.Start(info);

Upvotes: 1

Thang Pham
Thang Pham

Reputation: 621

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.

Upvotes: 0

Related Questions