如何重启控制台应用程序 c# mono MacOS

How to restart console app c# mono MacOS

我在 MacOS 上使用 Visual Studio。

当我发现异常时如何重启控制台应用程序?

Windows 代码无效:

                try
                {

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

您可以尝试使用此代码重新启动项目,但我建议您在 .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>
}