【问题标题】:How to restart console app c# mono MacOS如何重启控制台应用程序 c# mono MacOS
【发布时间】:2018-07-05 10:40:03
【问题描述】:

我使用 Visual Studio for MacOS。

捕获异常时如何重启控制台应用程序?

Windows 代码不起作用:

                try
                {

                }
                catch (Exception)
                {
                    Process.Start(Assembly.GetExecutingAssembly().Location);
                    Environment.Exit(0);
                }

【问题讨论】:

  • 要使用mono启动应用程序,需要运行[mono xxx.exe]而不是直接调用exe名称。
  • @scegg, "/Users/mac/Projects/Taxi2PartnerMac/Taxi2PartnerMac/bin/Debug/Taxi2PartnerMac.exe"
  • 抱歉,我刚刚编辑了我的评论。您可以尝试将单声道作为进程启动并将此位置作为参数传递。
  • @scegg,我试着去做
  • 字符串路径 = “单声道” + Assembly.GetExecutingAssembly().Location; Process.Start(路径);

标签: c# macos mono


【解决方案1】:

您可以尝试使用此代码重新启动项目,但我建议您在 .exe 上启动此项目,它可能无法在 Visual Studio 上运行。

try
{
     //"The code you wanna try"
}
catch
{
     System.Diagnostics.Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null);</i>
}

【讨论】:

  • 是的,我从终端运行 .exe 程序
  • 您能否仅在主字符串上尝试代码,以便我们了解代码是否有效。我的意思是不要在尝试时使用它,抓住它。
  • 代码同样有效 Process.Start(Assembly.GetExecutingAssembly().Location); Environment.Exit(0);
猜你喜欢
  • 1970-01-01
  • 2011-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-07
  • 1970-01-01
相关资源
最近更新 更多