代码之家  ›  专栏  ›  技术社区  ›  mostlytech

ProcessStartInfo.UseShellExecute=true,等待进程退出

  •  4
  • mostlytech  · 技术社区  · 16 年前

    我想使用shell可执行文件来尊重用户对要启动的应用程序的偏好,但我还需要知道特定应用程序何时关闭。

    Process editProcess = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = filename;
    startInfo.Verb = "edit";
    startInfo.UseShellExecute = true;
    editProcess.StartInfo = startInfo;
    
    // start the default editor
    editProcess.Start();
    editProcess.WaitForExit();
    

    WaitForExit似乎在shell进程退出时返回,而不是在实际进程退出时返回。

    有没有一种更好的方法来知道启动的应用程序何时退出,而不是手动解析注册表,找到正确的应用程序来启动,然后在没有shell execute的情况下显式启动该应用程序?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Dan    16 年前

    处理进程退出事件:

    editProcess.Exited += process_Exited;
    
    推荐文章