Process.Close() 不会终止创建的进程,c# [英] Process.Close() is not terminating created process,c#

查看:34
本文介绍了Process.Close() 不会终止创建的进程,c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 C# 应用程序,它使用 System.Diagnostics.Process 类来创建一个进程,使用

I've written a C# application which uses System.Diagnostics.Process class to create a process, using

 Process P1 = new Process();
 P1.FileName = "myexe.exe";

以及其他适当的设置.

我已将其链接到一个运行约 10 分钟的 exe 文件.(我正在编写程序来测量程序的运行时间).现在,我想中止正在运行的进程.所以我在取消按钮的事件中写道,

I've linked it to an exe file which runs for about 10 minutes. (I'm writing program to measure run-time of programs). Now in between I want to abort the running process. So I wrote in the cancel button's event,

 Process.Close();

但是在任务管理器中我仍然看到 myexe.exe 正在运行,它没有被中止.怎么办?

But in the task manager I still see myexe.exe running, it doesn't get aborted. What to do?

推荐答案

Process.Close() 并不是要中止进程 - 它只是为了释放您对进程和相关资源的本地"视图.

Process.Close() isn't meant to abort the process - it's just meant to release your "local" view on the process, and associated resources.

我想你的意思是 Process.Kill()Process.CloseMainWindow().就我个人而言,我会尝试找到一种更优雅的方式来关闭它.

I think you mean Process.Kill() or Process.CloseMainWindow(). Personally I'd try to find a more graceful way of shutting it down though.

这篇关于Process.Close() 不会终止创建的进程,c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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