Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Processes, Threads, and Stacks

The .NET Framework provides managed execution of code. However, managed applications live alongside unmanaged applications, and need to coexist. It can be useful for a managed application to have access to information about the atoms of unmanaged execution, namely operating system processes and threads. Additionally, since “managed execution” implies the existence of some overarching facility monitoring the execution process itself, it is not unreasonable to wish for access to detailed information about the execution process. Both of these needs are met by the classes in the System.Diagnostics namespace, providing access to unmanaged processes and threads, as well as access to managed stack frames. Access to managed threads and AppDomains, which are the managed equivalent of processes, is accomplished using the System and System.Threading namespaces.

Launching a New Process

The Process class can be used to launch new operating system processes, enumerate and kill existing ones, and monitor the vital statistics of a running process. The Process.Start method has overloads that range from taking the filename of an EXE to launch to taking a populated ProcessStartInfo instance, which fully specifies the parameters for process launching. The latter approach can also be used to capture and redirect the launched process’s stdin, stdout and stderr, as the following sample demonstrates:

public void LaunchDirCommand() { ProcessStartInfo psi = new ProcessStartInfo(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata