Share via


AsyncLazy<T>.DisposeValue Method

Definition

Disposes of the lazily-initialized value if disposable, and causes all subsequent attempts to obtain the value to fail.

public void DisposeValue ();
member this.DisposeValue : unit -> unit
Public Sub DisposeValue ()

Remarks

This call will block on disposal (which may include construction of the value itself if it has already started but not yet finished) if it is the first call to dispose of the value.

Calling this method will put this object into a disposed state where future calls to obtain the value will throw ObjectDisposedException.

If the value has already been produced and implements IDisposable or IAsyncDisposable, it will be disposed of. If the value factory has already started but has not yet completed, its value will be disposed of when the value factory completes.

If prior calls to obtain the value are in flight when this method is called, those calls may complete and their callers may obtain the value, although Dispose() may have been or will soon be called on the value, leading those users to experience a ObjectDisposedException.

Note all conditions based on the value implementing IDisposable or IAsyncDisposable is based on the actual value, rather than the T type argument. This means that although T may be IFoo (which does not implement IDisposable), the concrete type that implements IFoo may implement IDisposable and thus be treated as a disposable object as described above.

Applies to