# ValueSnapshot<T> Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ValueSnapshot<T>](/reference/api/csharp/aspire.hosting/valuesnapshot-1.md)
- Kind: `Methods`
- Members: `3`

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.

## GetValueAsync(CancellationToken)

- Name: `GetValueAsync(CancellationToken)`
- Returns: `Task<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ValueSnapshot.cs#L40-L45)

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.

```csharp
public sealed class ValueSnapshot<T>
{
    public Task<T> GetValueAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`

## SetException(Exception)

- Name: `SetException(Exception)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ValueSnapshot.cs#L69-L78)

Sets an exception that will be thrown by GetValueAsync. The first successful call (either SetValue or SetException) completes any pending GetValueAsync waiters.

```csharp
public sealed class ValueSnapshot<T>
{
    public void SetException(
        Exception exception)
    {
        // ...
    }
}
```

## Parameters

- `exception` (`Exception`)

## SetValue(T)

- Name: `SetValue(T)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ValueSnapshot.cs#L53-L60)

Sets (or updates) the value. The first successful call completes any pending GetValueAsync waiters. Subsequent calls replace the current value.

```csharp
public sealed class ValueSnapshot<T>
{
    public void SetValue(
        T value)
    {
        // ...
    }
}
```

## Parameters

- `value` (`T`)
