
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
484
|
Chapter 8: Diagnostics
Setting the priority above AboveNormal should be done in only very specialized situa-
tions for short durations of time, as it can starve other processes on the machine. The
operating system uses the priority level to determine scheduling for the processors,
and if one process is set to a higher priority for a long time, the processes with lesser
priority may never finish.
See Also
See the “Process Class,” “ProcessStartInfo Class,” and “ProcessPriorityClass Enumer-
ation” topics in the MSDN documentation.
8.18 Looking at Your Runtime Environment
and Seeing What You Can Do About It
Problem
You want a way to easily gather information about the environment your program is
running under to assist in troubleshooting customer issues.
Solution
Write a utility function that can gather this information for the process using the
System.Environment class members. To view and manipulate the environment vari-
ables, use the
GetEnvironmentVariables, GetEnvironmentVariable, and Set-
EnvironmentVariable
methods:
Console.WriteLine("Current environment settings:");
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables( ))
{
Console.WriteLine("\t\tEnvironment Variable {0}: Value {1}", de.Key, de.Value);
}
Console.WriteLine("\tSetting environment variable MYENVVAR to {0}", ...