process

P

Perico

hi to all,

If to start a process i can use this way...

System.Diagnostics.Process.Start()

How could close a proccess in my machine? there isnt a
method like End()

Thanks in advance.
Perico.
 
J

Jon Skeet [C# MVP]

Perico said:
If to start a process i can use this way...

System.Diagnostics.Process.Start()

How could close a proccess in my machine? there isnt a
method like End()

See Process.Kill and Process.CloseMainWindow - but you should consider
carefully before doing such a thing.
 
P

Perico

Hi Madhu
im viewing the url that you tell me, but i dont
understand one thing...

In the msdn speaks about the anormal termination of a
program using the kill method, but i try use this method
in my visual studio editor, and i cant find the kill
method...

Im using
System.Diagnostics.Process.Kill() but the visual studio
dont recognize this...

Probably im using the msdn in a wrong way. Could you give
me an advice about this?

Thanks Madhu.
Regards.
Perico
 
M

Morten Wennevik

You need the instance of a process to call its kill method

System.Diagnostics.Process.GetCurrentProcess().Kill();
System.Diagnostics.Process.GetProcessesByName("MyProcess").Kill();
 
M

Madhu [MVP]

Hi Perico,

Note that the Kill method of Process class is not a
static method that is the reason why

System.Diagnostics.Process.Kill() doesn't show in Visual
Studio.

Hope this helps...

Regards,
Madhu

MVP | MCSD.NET
 
M

Morten Wennevik

I was a bit fast there. GetProcessesByName returns an array of processes
so the line should read

System.Diagnostics.Process.GetProcessesByName("MyProcess")[0].Kill();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top