Share via


ThreadingTools.ApplyChangeOptimistically Method

Definition

Overloads

ApplyChangeOptimistically<T,TArg>(T, TArg, Func<T,TArg,T>)

Optimistically performs some value transformation based on some field and tries to apply it back to the field, retrying as many times as necessary until no other thread is manipulating the same field.

ApplyChangeOptimistically<T>(T, Func<T,T>)

Optimistically performs some value transformation based on some field and tries to apply it back to the field, retrying as many times as necessary until no other thread is manipulating the same field.

ApplyChangeOptimistically<T,TArg>(T, TArg, Func<T,TArg,T>)

Optimistically performs some value transformation based on some field and tries to apply it back to the field, retrying as many times as necessary until no other thread is manipulating the same field.

public:
generic <typename T, typename TArg>
 where T : class static bool ApplyChangeOptimistically(T % hotLocation, TArg applyChangeArgument, Func<T, TArg, T> ^ applyChange);
public static bool ApplyChangeOptimistically<T,TArg> (ref T hotLocation, TArg applyChangeArgument, Func<T,TArg,T> applyChange) where T : class;
static member ApplyChangeOptimistically : 'T * 'Arg * Func<'T, 'Arg, 'T (requires 'T : null and 'T : null)> -> bool (requires 'T : null)
Public Function ApplyChangeOptimistically(Of T As Class, TArg As Class) (ByRef hotLocation As T, applyChangeArgument As TArg, applyChange As Func(Of T, TArg, T)) As Boolean

Type Parameters

T

The type of data to apply the change to.

TArg

The type of argument passed to the applyChange.

Parameters

hotLocation
T

The field that may be manipulated by multiple threads.

applyChangeArgument
TArg

An argument to pass to applyChange.

applyChange
Func<T,TArg,T>

A function that receives both the unchanged value and applyChangeArgument, then returns the changed value.

Returns

true if the location's value is changed by applying the result of the applyChange function; false if the location's value remained the same because the last invocation of applyChange returned the existing value.

Remarks

Use this overload when applyChange requires a single item, as is common when updating immutable collection types. By passing the item as a method operand, the caller may be able to avoid allocating a closure object for every call.

Applies to

ApplyChangeOptimistically<T>(T, Func<T,T>)

Optimistically performs some value transformation based on some field and tries to apply it back to the field, retrying as many times as necessary until no other thread is manipulating the same field.

public:
generic <typename T>
 where T : class static bool ApplyChangeOptimistically(T % hotLocation, Func<T, T> ^ applyChange);
public static bool ApplyChangeOptimistically<T> (ref T hotLocation, Func<T,T> applyChange) where T : class;
static member ApplyChangeOptimistically : 'T * Func<'T, 'T (requires 'T : null and 'T : null)> -> bool (requires 'T : null)
Public Function ApplyChangeOptimistically(Of T As Class) (ByRef hotLocation As T, applyChange As Func(Of T, T)) As Boolean

Type Parameters

T

The type of data.

Parameters

hotLocation
T

The field that may be manipulated by multiple threads.

applyChange
Func<T,T>

A function that receives the unchanged value and returns the changed value.

Returns

true if the location's value is changed by applying the result of the applyChange function; false if the location's value remained the same because the last invocation of applyChange returned the existing value.

Applies to