Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

Process.Close() is not terminating created process,c#

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";

and other proper settings.

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();

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...