Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

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?

like image 232
Anirudh Goel Avatar asked Mar 23 '09 11:03

Anirudh Goel


1 Answers

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.

like image 92
Jon Skeet Avatar answered Oct 13 '22 19:10

Jon Skeet