Knowing Your Environment: the System.Environment Class - More Explanations
(Page 3 of 4 )
StackTrace: This method is very handy for debugging purposes. The methods are listed in reverse chronological order. One line is listed for each method call in the call stack.
//Gets current stack trace information.
Console .WriteLine( "nStackTrace: {0}n" , Environment .StackTrace);
SystemDirectory: An example of the fully qualified name of the system directory would be: C:WinNTSystem32
//Gets the fully qualified path of the system directory.
Console .WriteLine( "System Directory: {0}" , Environment .SystemDirectory);
TickCount: This property returns the number of milliseconds that have elapsed since the system started. Since the return value is a 32-bit signed integer, if the system keeps running for quite some time (around 25 days), the tick count will reach int32.MaxValue and jumps to Int32.MinValue which is a negative number, then increment to 0 in about 25 days.
//Gets the number of milliseconds elapsed since the system started.
Console .WriteLine( "The tick count is: {0}" , Environment .TickCount);
UserDomainName: This property returns the network domain name associated with the current user. It first attempts to get the domain name of the Windows NT 4.0 account name for the current user. If that fails, the second attempt will be to get the domain name associated with the user name provided by the UserName property. If that fails, then the host computer name is returned.
//Gets the network domain name associated with the current user.
Console .WriteLine( "User Domain Name: {0}" , Environment .UserDomainName);
UserInteractive: This property returns true if the current process is running in a user interactive mode. If it returns false, do not display modal dialogs because there is no GUI with which the user can interact.
//Gets a value indicating whether the current process is running in user
//interactive mode.
Console .WriteLine( "User Interactive? {0}" , Environment .UserInteractive);
UserName: This property gets the user name of the person who is currently logged on. It can be used to customize a particular application. For example, in a web application, you can check whether this user is part of an admin group. If so, you can provide the user extra privileges with which to access pages that are usually hidden from non-admin users.
//Gets the user name of the person who started the current thread.
Console .WriteLine( "UserName: {0}" , Environment .UserName);
Version: This property provides the version of the .NET runtime. Based on the version, you can determine what functionality to use. For example, in version 1.0 of the runtime, you can use the thread methods Suspend and Resume. But in higher versions (such as 2.0), these methods are deprecated. So knowing the runtime version helps you use the functionality that best fits your application.
//Gets a Version object that describes the major, minor, build, and revision
//numbers of the common language runtime.
Console .WriteLine( "Version: {0}" , Environment .Version.ToString());
WorkingSet: This property returns a 64-bit integer that contains the amount of physical memory that is mapped to the process context. You can call this property before and after loading a certain dll, which is handy when you want to know which dll is consuming the most memory and take additional steps to improve the performance of your application.
//Gets the amount of physical memory mapped to the process context.
Console .WriteLine( "Working Set: {0}" , Environment .WorkingSet);
Next: Methods >>
More .NET Articles
More By Ayad Boudiab