diff --git a/snippets/csharp/System/Environment/TickCount/Project.csproj b/snippets/csharp/System/Environment/TickCount/Project.csproj deleted file mode 100644 index aa9fd2ecaaf..00000000000 --- a/snippets/csharp/System/Environment/TickCount/Project.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - net6.0 - - - \ No newline at end of file diff --git a/snippets/csharp/System/Environment/TickCount/tickcount.cs b/snippets/csharp/System/Environment/TickCount/tickcount.cs deleted file mode 100644 index 4c3514b9e16..00000000000 --- a/snippets/csharp/System/Environment/TickCount/tickcount.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Sample for the Environment.TickCount property. - -// TickCount cycles between Int32.MinValue, which is a negative -// number, and Int32.MaxValue once every 49.8 days. This sample -// removes the sign bit to yield a nonnegative number that cycles -// between zero and Int32.MaxValue once every 24.9 days. - -using System; - -class Sample -{ - public static void Main() - { - int result = Environment.TickCount & Int32.MaxValue; - Console.WriteLine("TickCount: {0}", result); - } -} -/* -This example produces an output similar to the following: - -TickCount: 101931139 -*/ -// \ No newline at end of file diff --git a/snippets/fsharp/System/Environment/TickCount/fs.fsproj b/snippets/fsharp/System/Environment/TickCount/fs.fsproj deleted file mode 100644 index 4832d4205f6..00000000000 --- a/snippets/fsharp/System/Environment/TickCount/fs.fsproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net6.0 - - - - - - \ No newline at end of file diff --git a/snippets/fsharp/System/Environment/TickCount/tickcount.fs b/snippets/fsharp/System/Environment/TickCount/tickcount.fs deleted file mode 100644 index 404bbbdfa55..00000000000 --- a/snippets/fsharp/System/Environment/TickCount/tickcount.fs +++ /dev/null @@ -1,16 +0,0 @@ -// -// Sample for the Environment.TickCount property. - -// TickCount cycles between Int32.MinValue, which is a negative -// number, and Int32.MaxValue once every 49.8 days. This sample -// removes the sign bit to yield a nonnegative number that cycles -// between zero and Int32.MaxValue once every 24.9 days. - -open System - -let result = Environment.TickCount &&& Int32.MaxValue -printfn $"TickCount: {result}" - -// This example produces an output similar to the following: -// TickCount: 101931139 -// \ No newline at end of file diff --git a/snippets/visualbasic/System/Environment/TickCount/tickcount.vb b/snippets/visualbasic/System/Environment/TickCount/tickcount.vb deleted file mode 100644 index 06e5abba7b1..00000000000 --- a/snippets/visualbasic/System/Environment/TickCount/tickcount.vb +++ /dev/null @@ -1,21 +0,0 @@ -' - -' Sample for the Environment.TickCount property. -' TickCount cycles between Int32.MinValue, which is a negative -' number, and Int32.MaxValue once every 49.8 days. This sample -' removes the sign bit to yield a nonnegative number that cycles -' between zero and Int32.MaxValue once every 24.9 days. - -Class Sample - Public Shared Sub Main() - Dim result As Integer = Environment.TickCount And Int32.MaxValue - - Console.WriteLine("TickCount: {0}", result) - End Sub -End Class -' -'This example produces an output similar to the following: -' -'TickCount: 101931139 -' -' \ No newline at end of file diff --git a/xml/System/Environment.xml b/xml/System/Environment.xml index 055db9d8016..c9d3784d430 100644 --- a/xml/System/Environment.xml +++ b/xml/System/Environment.xml @@ -255,7 +255,7 @@ By definition, if this process starts in the root directory of a local or network drive, the value of this property is the drive name followed by a trailing slash (for example, "C:\\"). If this process starts in a subdirectory, the value of this property is the drive and subdirectory path, without a trailing slash (for example, "C:\mySubDirectory"). ## Examples - The following example demonstrates setting the property. + The following example demonstrates setting the property. :::code language="csharp" source="~/snippets/csharp/System/Environment/CurrentDirectory/Vars1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment/CurrentDirectory/Vars1.fs" id="Snippet4"::: @@ -461,12 +461,12 @@ If the `Main` method returns `void`, you can use this property to set the exit code that will be returned to the calling environment. If `Main` does not return `void`, this property is ignored. The initial value of this property is zero. > [!WARNING] -> The property is a signed 32-bit integer. To prevent the property from returning a negative exit code, you should not use values greater than or equal to 0x80000000. +> The property is a signed 32-bit integer. To prevent the property from returning a negative exit code, you should not use values greater than or equal to 0x80000000. Use a non-zero number to indicate an error. In your application, you can define your own error codes in an enumeration, and return the appropriate error code based on the scenario. For example, return a value of 1 to indicate that the required file is not present and a value of 2 to indicate that the file is in the wrong format. For a list of exit codes used by the Windows operating system, see [System Error Codes](/windows/win32/debug/system-error-codes) in the Windows documentation. ## Examples - The following is a simple app named Double.exe that doubles an integer value passed to it as a command-line argument. The value assigns error codes to the property to indicate error conditions. Note that you must add a reference to the System.Numerics.dll assembly to successfully compile the example. + The following is a simple app named Double.exe that doubles an integer value passed to it as a command-line argument. The value assigns error codes to the property to indicate error conditions. Note that you must add a reference to the System.Numerics.dll assembly to successfully compile the example. :::code language="csharp" source="~/snippets/csharp/System/Environment/ExitCode/double.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment/ExitCode/double.fs" id="Snippet1"::: @@ -846,7 +846,7 @@ In .NET 5 and later versions, for single-file publishing, the first element is t |`MyApp \\\alpha \\\\"beta`|`MyApp, \\\alpha, \\beta`| |`MyApp \\\\\"alpha \"beta`|`MyApp, \\"alpha, "beta`| - To obtain the command line as a single string, use the property. + To obtain the command line as a single string, use the property. ## Examples The following example displays the application's command line arguments. @@ -1502,9 +1502,9 @@ The following example creates environment variables for the property returns `true` only after the finalizer thread has been started. When the property returns `true`, you can determine whether an application domain is being unloaded or the CLR itself is shutting down by calling the method. This method returns `true` if finalizers are called because the application domain is unloading or `false` if the CLR is shutting down. + **.NET Framework only**: When the CLR unloads an application domain, it runs the finalizers on all objects that have a finalizer method in that application domain. When the CLR shuts down, it starts the finalizer thread on all objects that have a finalizer method. The property returns `true` only after the finalizer thread has been started. When the property returns `true`, you can determine whether an application domain is being unloaded or the CLR itself is shutting down by calling the method. This method returns `true` if finalizers are called because the application domain is unloading or `false` if the CLR is shutting down. - The property returns `false` if the finalizer thread has not been started. + The property returns `false` if the finalizer thread has not been started. By using this property, you can determine whether to access static variables in your finalization code. If either an application domain or the CLR is shutting down, you cannot reliably access any object that has a finalization method and that is referenced by a static field. This is because these objects may have already been finalized. @@ -1936,7 +1936,7 @@ The value returned by this API is fixed at .NET runtime startup for the process For more information about processor groups and logical processors, see [Processor Groups](/windows/win32/procthread/processor-groups). ## Examples - The following example demonstrates the property. + The following example demonstrates the property. :::code language="csharp" source="~/snippets/csharp/System/Environment/ProcessorCount/pc.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment/ProcessorCount/pc.fs" id="Snippet1"::: @@ -2303,12 +2303,12 @@ The following example creates environment variables for the property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. However, the property might not report as many method calls as expected due to code transformations that occur during optimization. + The property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. However, the property might not report as many method calls as expected due to code transformations that occur during optimization. > [!NOTE] > For a hierarchical view of the stack trace information by class, use the class. - The property formats the stack trace information for each method call as follows: + The property formats the stack trace information for each method call as follows: "at `FullClassName`.`MethodName`(`MethodParams`) in `FileName` :line `LineNumber` " @@ -2332,7 +2332,7 @@ The following example creates environment variables for the string terminates each line of the stack trace. ## Examples - The following example demonstrates the property. + The following example demonstrates the property. :::code language="csharp" source="~/snippets/csharp/System/Environment/StackTrace/stacktrace.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment/StackTrace/stacktrace.fs" id="Snippet1"::: @@ -2516,25 +2516,18 @@ The following example creates environment variables for the property is limited to the resolution of the system timer, which is typically in the range of 10 to 16 milliseconds. +This property returns the truncated result of . For version differences and information about update frequency, see the remarks. > [!IMPORTANT] -> Because the value of the property value is a 32-bit signed integer, if the system runs continuously, will increment from zero to for approximately 24.9 days, then jump to , which is a negative number, then increment back to zero during the next 24.9 days. You can work around this issue by calling the Windows [GetTickCount](/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount) function, which resets to zero after approximately 49.7 days, or by calling the [GetTickCount64](/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64) function. - - is different from the property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am. +> Because the value of the property value is a 32-bit signed integer, if the system runs continuously, increments from zero to for approximately 24.9 days, then jumps to , which is a negative number, then increments back to zero during the next 24.9 days. You can work around this issue by casting the result of to `uint`. This works because `int` and `uint` are a two's complement representation. This workaround is valid on all platforms. - Use the property to obtain the current local date and time on this computer. - -## Examples - The following example demonstrates how to retrieve the positive range of values returned by the property. The property cycles between , which is a negative number, and once every 49.8 days. This code sample removes the sign bit to yield a nonnegative number that cycles between zero and once every 24.9 days. + is different from the property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am. - :::code language="csharp" source="~/snippets/csharp/System/Environment/TickCount/tickcount.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Environment/TickCount/tickcount.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System/Environment/TickCount/tickcount.vb" id="Snippet1"::: +Use the property to obtain the current local date and time. ]]> + Environment.TickCount made consistent with Windows timeout behavior @@ -2571,7 +2564,19 @@ The following example creates environment variables for the Gets the number of milliseconds elapsed since the system started. The elapsed milliseconds since the system started. - To be added. + + [!NOTE] +> On Windows, in .NET 10 and earlier versions, including .NET Framework, the elapsed time **includes** non-awake time. In addition, the value updates at a fixed cadence of 10-16ms (typically 15.5ms). + + ]]> + + Environment.TickCount made consistent with Windows timeout behavior @@ -2625,9 +2630,9 @@ The following example creates environment variables for the property to obtain the user's domain name without the user name, and the property to obtain the user name without the domain name. For example, if a user's domain name and user name are CORPORATENETWORK\john, the property returns "CORPORATENETWORK". + The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the property to obtain the user's domain name without the user name, and the property to obtain the user name without the domain name. For example, if a user's domain name and user name are CORPORATENETWORK\john, the property returns "CORPORATENETWORK". - The property first attempts to get the domain name component of the Windows account name for the current user. If that attempt fails, this property attempts to get the domain name associated with the user name provided by the property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned. + The property first attempts to get the domain name component of the Windows account name for the current user. If that attempt fails, this property attempts to get the domain name associated with the user name provided by the property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned. ]]> @@ -2688,7 +2693,7 @@ The following example creates environment variables for the property reports `false` for a Windows process or a service like IIS that runs without a user interface. If this property is `false`, do not display modal dialogs or message boxes because there is no graphical user interface for the user to interact with. + The property reports `false` for a Windows process or a service like IIS that runs without a user interface. If this property is `false`, do not display modal dialogs or message boxes because there is no graphical user interface for the user to interact with. ## Examples The following example displays whether the current process is running in user interactive mode. @@ -2753,13 +2758,13 @@ The following example creates environment variables for the property to identify the user on the current thread, to the system and application for security or access purposes. It can also be used to customize a particular application for each user. + You can use the property to identify the user on the current thread, to the system and application for security or access purposes. It can also be used to customize a particular application for each user. - On Windows the property wraps a call to the Windows [GetUserName](/windows/win32/api/winbase/nf-winbase-getusernamea) function. The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the property to obtain the user's domain name and the property to obtain the user name. + On Windows the property wraps a call to the Windows [GetUserName](/windows/win32/api/winbase/nf-winbase-getusernamea) function. The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the property to obtain the user's domain name and the property to obtain the user name. - On Unix platforms the property wraps a call to the `getpwuid_r` function. + On Unix platforms the property wraps a call to the `getpwuid_r` function. - If an ASP.NET application runs in a development environment, the property returns the name of the current user. In a published ASP.NET application, this property returns the name of the application pool account (such as Default AppPool). + If an ASP.NET application runs in a development environment, the property returns the name of the current user. In a published ASP.NET application, this property returns the name of the application pool account (such as Default AppPool). ## Examples The following example displays the user name of the person who started the current thread. @@ -2818,12 +2823,12 @@ The following example creates environment variables for the property returns the .NET runtime version number. + For .NET Core 3.x and .NET 5+, the property returns the .NET runtime version number. - For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, the property returns a object whose string representation has the form `4.0.30319.xxxxx`. For the .NET Framework 4.6 and later versions, and .NET Core versions before 3.0, it has the form `4.0.30319.42000`. + For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, the property returns a object whose string representation has the form `4.0.30319.xxxxx`. For the .NET Framework 4.6 and later versions, and .NET Core versions before 3.0, it has the form `4.0.30319.42000`. > [!WARNING] -> For the .NET Framework 4.5 and later, we do not recommend using the property to detect the version of the runtime; instead, you can determine the version of the common language runtime by querying the registry. For more information, see [How to: Determine Which .NET Framework Versions Are Installed](/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed). +> For the .NET Framework 4.5 and later, we do not recommend using the property to detect the version of the runtime; instead, you can determine the version of the common language runtime by querying the registry. For more information, see [How to: Determine Which .NET Framework Versions Are Installed](/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed). For more information about the version of the common language runtime that is installed with each version of the .NET Framework, see [Versions and Dependencies](/dotnet/framework/migration-guide/versions-and-dependencies).