.NET
  Home arrow .NET arrow Page 3 - Knowing Your Environment: the System.Envir...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Knowing Your Environment: the System.Environment Class
By: Ayad Boudiab
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-05-12

    Table of Contents:
  • Knowing Your Environment: the System.Environment Class
  • More Properties
  • More Explanations
  • Methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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);


    TickCountThis 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);


    UserInteractiveThis 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);

    VersionThis 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());

    WorkingSetThis 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);

    More .NET Articles
    More By Ayad Boudiab


       · Hello everyone,Here is my latest article on the System.Environment class.Please...
     

    .NET ARTICLES

    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT