繁体   English   中英

C# Process.Start - 独立进程

[英]C# Process.Start - independent process

我只想运行另一个.exe ,然后关闭调用者。

就像是:

var info = new ProcessStartInfo
{
    WorkingDirectory = "myDirectory",
    FileName = "myFile.exe"
};
Process.Start(info);
Environment.Exit(0);

但是,子进程与父进程同时关闭。

  • 父级是一个应用程序,单击按钮后关闭。
  • 孩子是一个应用程序,它与父母(不需要)同时关闭。
  • 父级是一个启动器。
  • 子项是一个可以在您手动启动时工作的应用程序。

我尝试过其他解决方案,但它们都有相同的不良行为:

var info = new ProcessStartInfo
{
    WorkingDirectory = "myDirectory",
    FileName = "cmd",
    Arguments = $"/C myFile.exe",
    WindowStyle = ProcessWindowStyle.Hidden
};
Process.Start(info);
Environment.Exit(0);
var thread = new Thread(() =>
{
    var info = new ProcessStartInfo
    {
        WorkingDirectory = "myDirectory",
        FileName = "myFile.exe"
    };
    Process.Start(info);
});
thread.Start();
Environment.Exit(0);
Task.Factory.StartNew(() =>
{
    var info = new ProcessStartInfo
    {
        WorkingDirectory = "myDirectory",
        FileName = "myFile.exe"
    };
    Process.Start(info);
});

这很愚蠢......它在调试模式下不起作用。 这不是错误,而是故意的(幸运的是它是这样设计的)。

(使用 Rider JetBrains)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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