ale*_*ale 11 c# console console-application
当用户按"R"时,我需要重新启动应用控制台.
我有这个
Console.WriteLine(message, "Rebuild Log Files"
+ " Press Enter to finish, or R to restar the program...");
string restar = Console.ReadLine();
if(restar.ToUpper() == "R")
{
//here the code to restart the console...
}
Run Code Online (Sandbox Code Playgroud)
谢谢
Jep*_*sen 12
// Starts a new instance of the program itself
System.Diagnostics.Process.Start(Application.ExecutablePath);
// Closes the current process
Environment.Exit(0);
Run Code Online (Sandbox Code Playgroud)
static void Main(string[] args)
{
var info = Console.ReadKey();
if (info.Key == ConsoleKey.R)
{
var fileName = Assembly.GetExecutingAssembly().Location;
System.Diagnostics.Process.Start(fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
我不认为你真的需要重启整个应用程序.按下R后只需运行所需的方法.无需重启.
另一种简单的方法
//Start process, friendly name is something like MyApp.exe (from current bin directory)
System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
//Close the current process
Environment.Exit(0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42520 次 |
| 最近记录: |