# ValueSnapshot<T>

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ValueSnapshot.cs)

Provides an asynchronously initialized value that: - Can be awaited via GetValueAsync() until the first value or exception is set. - Exposes the latest value after it has been set (supports re-setting). - Tracks whether a value or exception was ever set via IsValueSet. - Supports setting an exception that will be thrown by GetValueAsync. Thread-safe for concurrent SetValue / SetException / GetValueAsync calls.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class ValueSnapshot<T>
    where T : notnull
{
    // ...
}
```

## Constructors

- [ValueSnapshot](/reference/api/csharp/aspire.hosting/valuesnapshot-1/constructors.md#constructor)

## Properties

- [IsValueSet](/reference/api/csharp/aspire.hosting/valuesnapshot-1/properties.md#isvalueset) : `bool` `get` -- True once a value or exception has been set at least once.

## Methods

- [GetValueAsync(CancellationToken)](/reference/api/csharp/aspire.hosting/valuesnapshot-1/methods.md#getvalueasync-cancellationtoken) : `Task<T>` -- Await the current value: - If a value has already been set, returns it immediately. - If an exception has been set, throws it. - Otherwise waits until the first value or exception is set. Always returns the latest value at the moment of completion or throws the exception.
- [SetException(Exception)](/reference/api/csharp/aspire.hosting/valuesnapshot-1/methods.md#setexception-exception) -- Sets an exception that will be thrown by GetValueAsync. The first successful call (either SetValue or SetException) completes any pending GetValueAsync waiters.
- [SetValue(T)](/reference/api/csharp/aspire.hosting/valuesnapshot-1/methods.md#setvalue-t) -- Sets (or updates) the value. The first successful call completes any pending GetValueAsync waiters. Subsequent calls replace the current value.
