Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

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# in a Nutshell

C# in a Nutshell

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

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Joe Mayo

Publisher Resources

ISBN: 0596005261Catalog PageErrata