From bd10486ef890dbbe64d46343f52396df44ce63c2 Mon Sep 17 00:00:00 2001 From: David Engel Date: Thu, 17 Jul 2025 13:38:55 -0700 Subject: [PATCH 1/2] Fix incorrect snippet description Addresses #11583 --- xml/System.Data.SqlClient/SqlCommand.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System.Data.SqlClient/SqlCommand.xml b/xml/System.Data.SqlClient/SqlCommand.xml index 3b4b573a6d5..cfad0befcc8 100644 --- a/xml/System.Data.SqlClient/SqlCommand.xml +++ b/xml/System.Data.SqlClient/SqlCommand.xml @@ -554,7 +554,7 @@ class Program { ## Examples - The following example creates a , passing in the connection string and command text. + The following example creates a , passing in the command text. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.SqlCommand1 Example/CS/source.cs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlCommand/.ctor/source.vb" id="Snippet1"::: From aee73fc0e2ec14ab77ae5b30ffcc868692c5640b Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:55:38 -0700 Subject: [PATCH 2/2] Update docs for CompareExchange\ (#11422) --- xml/System.Threading/Interlocked.xml | 52 +++++++++------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/xml/System.Threading/Interlocked.xml b/xml/System.Threading/Interlocked.xml index 292d8139635..85fb1ee7f2d 100644 --- a/xml/System.Threading/Interlocked.xml +++ b/xml/System.Threading/Interlocked.xml @@ -68,11 +68,9 @@ The and methods increment or decrement a variable and store the resulting value in a single operation. On most computers, incrementing a variable is not an atomic operation, requiring the following steps: -1. Load a value from an instance variable into a register. - -2. Increment or decrement the value. - -3. Store the value in the instance variable. +1. Load a value from an instance variable into a register. +2. Increment or decrement the value. +3. Store the value in the instance variable. If you do not use and , a thread can be preempted after executing the first two steps. Another thread can then execute all three steps. When the first thread resumes execution, it overwrites the value in the instance variable, and the effect of the increment or decrement performed by the second thread is lost. @@ -82,7 +80,6 @@ Ensure that any write or read access to a shared variable is atomic. Otherwise, the data might be corrupted or the loaded value might be incorrect. - ## Examples The following code example shows a thread-safe resource locking mechanism. @@ -611,8 +608,6 @@ ## Remarks If `comparand` and the value in `location1` are equal, then `value` is stored in `location1`. Otherwise, no operation is performed. The compare and exchange operations are performed as an atomic operation. The return value of is the original value in `location1`, whether or not the exchange takes place. - - ## Examples The following code example demonstrates a thread-safe method that accumulates a running total of values. Two threads add a series of values using the thread-safe method and ordinary addition, and when the threads complete the totals are compared. On a dual-processor computer, there is a significant difference in the totals. @@ -729,13 +724,11 @@ ## Remarks If `comparand` and the value in `location1` are equal, then `value` is stored in `location1`. Otherwise, no operation is performed. The compare and exchange operations are performed as an atomic operation. The return value of is the original value in `location1`, whether or not the exchange takes place. - - ## Examples The following code example demonstrates a thread-safe method that accumulates a running total. The initial value of the running total is saved, and then the method is used to exchange the newly computed total with the old total. If the return value is not equal to the saved value of the running total, then another thread has updated the total in the meantime. In that case, the attempt to update the running total must be repeated. > [!NOTE] -> The method, introduced in version 2.0 of the .NET Framework, provides a more convenient way to accumulate thread-safe running totals for integers. +> The method provides a more convenient way to accumulate thread-safe running totals for integers. :::code language="csharp" source="~/snippets/csharp/System.Threading/Interlocked/CompareExchange/source2.cs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.Interlocked CompareExchange0/VB/source.vb" id="Snippet1"::: @@ -877,7 +870,7 @@ If `comparand` and the value in `location1` are equal, then `value` is stored in `location1`. Otherwise, no operation is performed. The compare and exchange operations are performed as an atomic operation. The return value of this method is the original value in `location1`, whether or not the exchange takes place. > [!NOTE] -> is a platform-specific type. +> is a platform-specific type. ]]> @@ -951,12 +944,12 @@ ## Remarks > [!IMPORTANT] -> The method overload provides a type-safe alternative for reference types. We recommend that you call it instead of this overload. +> The method overload provides a generic alternative that can be used for concrete reference types. If `comparand` and the object in `location1` are equal by reference, then `value` is stored in `location1`. Otherwise, no operation is performed. The compare and exchange operations are performed as an atomic operation. The return value of is the original value in `location1`, whether or not the exchange takes place. > [!NOTE] -> The objects are compared for reference equality rather than value equality. As a result, two boxed instances of the same value type (for example, the integer 3) always appear to be unequal and no operation is performed. Do not use this overload with value types. +> The objects are compared for reference equality rather than value equality. As a result, two boxed instances of the same value type (for example, the integer 3) always appear to be unequal and no operation is performed. Do not use this overload with value types. ]]> @@ -1341,27 +1334,23 @@ If `comparand` and the object in `location1` are equal by reference, then `value - The type to be used for , , and . This type must be a reference type. + The type to be used for , , and . The destination, whose value is compared by reference with and possibly replaced. This is a reference parameter ( in C#, in Visual Basic). The value that replaces the destination value if the comparison by reference results in equality. The value that is compared by reference to the value at . - Compares two instances of the specified reference type for reference equality and, if they are equal, replaces the first one, as an atomic operation. + Compares two instances of the specified type for reference equality and, if they're equal, replaces the first one, as an atomic operation. The original value in . method for the value types , , , , and , but there is no support for other value types. - -> [!NOTE] -> This method overload is preferable to the method overload, because the latter requires the destination object to be accessed late-bound. +If `comparand` and the value in `location1` are equal by reference, then `value` is stored in `location1`. Otherwise, no operation is performed. The comparison and the exchange are performed as an atomic operation. The return value of this method is the original value in `location1`, whether or not the exchange takes place. ]]> The address of is a null pointer. - An unsupported is specified. + An unsupported is specified. On .NET 8 and earlier versions, must be a reference type. On .NET 9 and later versions, must be a reference, primitive, or enum type. @@ -2008,7 +1997,7 @@ If `comparand` and the object in `location1` are equal by reference, then `value ## Remarks > [!IMPORTANT] -> The method overload provides a type-safe alternative for reference types. We recommend that you call it instead of this overload. +> The method overload provides a generic alternative that can be used for concrete reference types. ]]> @@ -2371,23 +2360,14 @@ If `comparand` and the object in `location1` are equal by reference, then `value - The type to be used for and . This type must be a reference type. + The type to be used for and . The variable to set to the specified value. This is a reference parameter ( in C#, in Visual Basic). The value to which the parameter is set. - Sets a variable of the specified type to a specified value and returns the original value, as an atomic operation. + Sets a variable of the specified type to a specified value and returns the original value, as an atomic operation. The original value of . - - method for the , , , , and value types, but there is no support for other value types. - -> [!NOTE] -> This method overload is preferable to the method overload, because the latter requires late-bound access to the destination object . - ]]> - + To be added. The address of is a pointer. - An unsupported is specified. + An unsupported is specified. On .NET 8 and earlier versions, must be a reference type. On .NET 9 and later versions, must be a reference, primitive, or enum type.