O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Process

Synopsis

This class represents a system process. Use it to start, stop, and interact with a process. To launch a new process, create an instance of ProcessStartInfo, set its properties, and pass it to the single-argument form of the static Start() method. This offers a great deal of control over process creation. To launch a process without customizing its StartInfo, simply call the one-string or two-string argument form of the static Start() method. The first string argument is the name of the program, batch file, or document to start, and the optional second argument contains any command-line arguments. You can also explicitly create a new instance of Process, set its StartInfo property, and call the Start() method to start the process.

GetCurrentProcess() creates a Process instance that represents the current process. Enumerate all running processes on the system by using GetProcesses(). Use GetProcessesByName() to get all processes for a given program. GetProcessById() retrieves a Process given its process ID.

Use CloseMainWindow() to shut down a process that has a user interface. You can terminate a process with Kill(), but this forces an abnormal termination, which may result in data corruption. If you would like to raise an event when the process finishes executing, use Exited (EnableRaisingEvents must be set to true).

Most of the properties allow you to access general information about the running process. However, this information is populated at the time ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required