Mono Class Library: System.Threading.Interlocked Overview | Members

System.Threading.Interlocked.CompareExchange Method

Compares two object variables for equality and stores a specified object if they are equal.

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public static object CompareExchange (ref object location1, object value, object comparand)

Parameters

location1
A object reference that is set to value if the object to which it refers is equal to comparand.
value
The reference that will replace the value of location1 if location1 and comparand are equal.
comparand
An object to be compared to that referred to by location1.

Returns

A object containing the original value of location1.

Exceptions

TypeReason
ArgumentNullExceptionThe address of location1 is null .

Remarks

The compare and store operations are performed as an atomic operation.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0