简体   繁体   中英

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?

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.

Found it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM