Environment Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.
Inheritance Hierarchy
System..::.Object
System..::.Environment
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public NotInheritable Class Environment
public static class Environment
The Environment type exposes the following members.
Properties
Name | Description | |
---|---|---|
CurrentDirectory | Gets the fully qualified path of the current working directory. | |
CurrentManagedThreadId | Gets a unique identifier for the current managed thread. | |
HasShutdownStarted | Gets a value indicating whether the common language runtime is shutting down or the current application domain is unloading. | |
NewLine | Gets the newline string defined for this environment. | |
OSVersion | Gets an OperatingSystem object that contains the current platform identifier and version number. | |
ProcessorCount | Gets the number of processors on the current machine. | |
TickCount | Gets the number of milliseconds elapsed since the system started. | |
Version | Gets a Version object that describes the major, minor, build, and revision numbers of the common language runtime. |
Top
Methods
Name | Description | |
---|---|---|
FailFast(String) | Security Critical. Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft. | |
FailFast(String, Exception) | Security Critical. Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and exception information in error reporting to Microsoft. | |
GetFolderPath | Gets the path to the system special folder identified by the specified enumeration. |
Top
Remarks
Use the Environment class to retrieve information such as command-line arguments, the exit code, environment variable settings, contents of the call stack, time since last system boot, and the version of the common language runtime.
Examples
The following example demonstrates displays a list of information about the current environment.
Note
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8.
' Sample for Environment class summary
Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
outputBlock.Text &= "-- Environment members --" & vbCrLf
outputBlock.Text &= String.Format("ExitCode: {0}", Environment.ExitCode) & vbCrLf
outputBlock.Text &= String.Format("HasShutDownStarted: {0}", Environment.HasShutdownStarted) & vbCrLf
outputBlock.Text &= String.Format("NewLine: {0} first line{0} second line{0}" & _
" third line", Environment.NewLine) & vbCrLf
outputBlock.Text &= String.Format("OSVersion: {0}", Environment.OSVersion) & vbCrLf
outputBlock.Text &= String.Format("TickCount: {0}", Environment.TickCount) & vbCrLf
outputBlock.Text &= String.Format("Version: {0}", Environment.Version) & vbCrLf
End Sub
End Class
// Sample for Environment class summary
using System;
class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
outputBlock.Text += "-- Environment members --" + "\n";
outputBlock.Text += String.Format("ExitCode: {0}", Environment.ExitCode) + "\n";
outputBlock.Text += String.Format("HasShutdownStarted: {0}", Environment.HasShutdownStarted) + "\n";
outputBlock.Text += String.Format("NewLine: {0} first line{0} second line{0} third line",
Environment.NewLine) + "\n";
outputBlock.Text += String.Format("OSVersion: {0}", Environment.OSVersion.ToString()) + "\n";
outputBlock.Text += String.Format("TickCount: {0}", Environment.TickCount) + "\n";
outputBlock.Text += String.Format("Version: {0}", Environment.Version.ToString()) + "\n";
}
}
Version Information
Windows Phone OS
Supported in: 8.1, 8.0, 7.1, 7.0
Platforms
Windows Phone
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.