。C#/。NET:关闭另一个进程的主窗口之外 [英] C#/.NET: Closing another process outside the main window

查看:394
本文介绍了。C#/。NET:关闭另一个进程的主窗口之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just wanna ask your opinion/suggestion on how to 'terminate' a running application/process is C#

现在,我有以下的codeS:

Right now, I do have the following codes:

    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();但什么也没有发生。

I also tried myProcess.Close(); but nothing's happening.

推荐答案

您应该看看

Process.HasExited物业

一个进程可以独立终止   你的code。如果你开始的   使用该组件的过程中,   系统更新HasExited的值   自动,即使相关的   流程独立退出。

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:关闭另一个进程的主窗口之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆