Table of Contents

Class TryLockTryDo

Namespace
ToSic.Sys.Locking
Assembly
ToSic.Sys.Core.dll

Execute something if a condition is met, but do it within a lock to avoid duplicate runs

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public class TryLockTryDo
Inheritance
object
TryLockTryDo

Constructors

TryLockTryDo(object?)

Execute something if a condition is met, but do it within a lock to avoid duplicate runs

public TryLockTryDo(object? lockObject = null)

Parameters

lockObject object

Fields

LockCount

public int LockCount

Field Value

int

PreLockCount

public int PreLockCount

Field Value

int

Methods

Call<TResult>(Func<bool>, Func<TResult>, Func<TResult>)

Get / Generate a value inside a lock with double-check.

public (TResult Result, bool Generated, string Message) Call<TResult>(Func<bool> conditionToGenerate, Func<TResult> generator, Func<TResult> cacheOrFallback)

Parameters

conditionToGenerate Func<bool>

Function to call checking if we need to generate the result

generator Func<TResult>

the generator

cacheOrFallback Func<TResult>

fallback to provide if no loading should happen - typically a previously cached result or default data

Returns

(TResult Result, bool Generated, string Message)

Type Parameters

TResult

Do(Func<bool>, Action)

public void Do(Func<bool> condition, Action action)

Parameters

condition Func<bool>
action Action