SystemThreadingExtensionApplyChangeOptimisticallyT, TArg(T, TArg, FuncT, 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.
命名空间: TouchSocket.Core程序集: TouchSocket.Core (在 TouchSocket.Core.dll 中) 版本:4.0.0-beta.143+5fcca7a4e70968794985dc3793adc50531308be6
public static bool ApplyChangeOptimistically<T, TArg>(
ref T hotLocation,
TArg applyChangeArgument,
Func<T, TArg, T> applyChange
)
where T : class
Public Shared Function ApplyChangeOptimistically(Of T As Class, TArg) (
ByRef hotLocation As T,
applyChangeArgument As TArg,
applyChange As Func(Of T, TArg, T)
) As Boolean
static member ApplyChangeOptimistically :
hotLocation : 'T byref *
applyChangeArgument : 'TArg *
applyChange : Func<'T, 'TArg, 'T> -> bool when 'T : not struct
- hotLocation T
- The field that may be manipulated by multiple threads.
- applyChangeArgument TArg
- An argument to pass to applyChange.
- applyChange FuncT, TArg, T
- A function that receives both the unchanged value and applyChangeArgument, then returns the changed value.
- T
- The type of data to apply the change to.
- TArg
- The type of argument passed to the applyChange.
Boolean if the location's value is changed by applying the result of the
applyChange function;
if the location's value remained the same because the last invocation of
applyChange returned the existing value.
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.