Class AsyncLazyInitializer
- Namespace
- Microsoft.VisualStudio.Threading
- Assembly
- Microsoft.VisualStudio.Threading.dll
Lazily executes a delegate that has some side effect (typically initializing something) such that the delegate runs at most once.
public class AsyncLazyInitializer
- Inheritance
-
AsyncLazyInitializer
- Inherited Members
Constructors
AsyncLazyInitializer(Func<Task>, JoinableTaskFactory?)
Initializes a new instance of the AsyncLazyInitializer class.
public AsyncLazyInitializer(Func<Task> action, JoinableTaskFactory? joinableTaskFactory = null)
Parameters
action
Func<Task>The action to perform at most once, that has some desirable side-effect.
joinableTaskFactory
JoinableTaskFactoryThe factory to use when invoking the
action
in InitializeAsync(CancellationToken) to avoid deadlocks when the main thread is required by theaction
.
Properties
IsCompleted
Gets a value indicating whether the action has executed completely, regardless of whether it threw an exception.
public bool IsCompleted { get; }
Property Value
IsCompletedSuccessfully
Gets a value indicating whether the action has executed completely without throwing an exception.
public bool IsCompletedSuccessfully { get; }
Property Value
Methods
Initialize(CancellationToken)
Executes the action given in the constructor if it has not yet been executed, or waits for it to complete if in progress from a prior call.
public void Initialize(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Exceptions
- Exception
Any exception thrown by the action is rethrown here.
InitializeAsync(CancellationToken)
Executes the action given in the constructor if it has not yet been executed, or waits for it to complete if in progress from a prior call.
public Task InitializeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
- Task
A task that tracks completion of the action.
Exceptions
- Exception
Any exception thrown by the action is rethrown here.