一款简单易用的基础网络通讯组件库。

SystemThreadingExtensionApplyChangeOptimisticallyT(T, FuncT, 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.

Definition

命名空间: TouchSocket.Core
程序集: TouchSocket.Core (在 TouchSocket.Core.dll 中) 版本:4.0.0-beta.143+5fcca7a4e70968794985dc3793adc50531308be6
C#
public static bool ApplyChangeOptimistically<T>(
	ref T hotLocation,
	Func<T, T> applyChange
)
where T : class

参数

hotLocation  T
The field that may be manipulated by multiple threads.
applyChange  FuncT, T
A function that receives the unchanged value and returns the changed value.

类型参数

T
The type of data.

返回值

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.

参见