C#/.NET : Closing another process outside the main window

标签 c# .net process

我只想问你关于如何“终止”正在运行的应用程序/进程的意见/建议是 C#

现在,我有以下代码:

    Process myProcess;
    private void btnOpen_Click(object sender, RoutedEventArgs e)
    {
        DirectoryInfo di = new DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.Programs));
        myProcess = Process.Start(di + @"\Wosk\Wosk.appref-ms"); // opening a file coming for Startup Menu
    }

    private void btnClose_Click(object sender, RoutedEventArgs e)
    {
        myProcess.Kill(); // not working - Cannot process request because the process has exited
    }

我也试过 myProcess.Close();但什么也没有发生。

最佳答案

你应该看看

Process.HasExited Property

A process can terminate independently of your code. If you started the process using this component, the system updates the value of HasExited automatically, even if the associated process exits independently.

关于C#/.NET : Closing another process outside the main window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2532202/

相关文章:

linux - 在 GNU/Linux 上获取由 MONO 执行的进程

Java process.waitFor() 不返回

c# - 为什么我用 Any CPU 编译的应用程序在我的 64 位机器上作为 32 位进程运行?

c# - 不包含 "foo"的定义

c# - RequiredFieldValidator 验证禁用的文本框

c# - Winforms 中的 DatagridView,SqlDataReader 是否在循环结束时自动关闭?

c# - List<> 和 IEnumerable<> 开放类型的关系

linux - 对于 SystemTap 脚本,如何确保捕获进程正在结束的事实?

c# - MVC C# 在不删除数据库的情况下更改数据库结构

c# - StructureMap 中的 AddConcreteType 和 TheDefaultIsConcreteType 有什么区别?