Class LatestBackgroundResult<T>
Manages a single background computation, exposing only the most recent result thread-safely.
public sealed class LatestBackgroundResult<T> where T : class
Type Parameters
TThe type of result produced by the calculation.
- Inheritance
-
objectLatestBackgroundResult<T>
- Extension Methods
Remarks
Starting a new computation automatically cancels and discards any in-progress one.
Properties
Result
The most recent successfully completed result, or null if no result is available yet.
public T? Result { get; }
Property Value
- T
Methods
Cancel()
Cancels any in-progress computation and discards the current result.
public void Cancel()
ConsumeResult()
Atomically reads and clears the latest result.
Returns null if no result is available.
public T? ConsumeResult()
Returns
- T
Run(Func<CancellationToken, T>)
Cancels any in-progress computation and starts computation on a background thread.
The result becomes available via Result or ConsumeResult() once complete.
public void Run(Func<CancellationToken, T> computation)
Parameters
computationFunc<CancellationToken, T>
Remarks
If the computation is canceled before it finishes, the result is silently discarded.