# IDurableStateManager Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.idurablestatemanager/)

## GetOrAddState(string) {#getoraddstate-1-string-437ca2b4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.idurablestatemanager/methods/getoraddstate-1-string-437ca2b4/)

```csharp
public abstract TState GetOrAddState<TState>(string name)
```

Gets an existing state component or creates it using the registered implementation of its application contract.

### Parameters

- `name` (`string`): The stable, ordinal, case-sensitive state name.

### Returns

The existing or newly created state instance.

### Exceptions

- `System.InvalidOperationException`: The name has an incompatible state type, the contract is not registered, or initialization has begun and the state does not exist.

## TryGetState(string, TState?) {#trygetstate-1-string-out-tstate-nullable-c48c5219}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.idurablestatemanager/methods/trygetstate-1-string-out-tstate-nullable-c48c5219/)

```csharp
public abstract bool TryGetState<TState>(string name, out TState? state)
```

Attempts to retrieve an existing state component without creating it.

### Parameters

- `name` (`string`): The stable, ordinal, case-sensitive state name.
- `state` (`TState?`): The existing state, if found.

### Returns

`true` if a compatible state exists; otherwise, `false`.

### Exceptions

- `System.InvalidOperationException`: The name has an incompatible state type.

## WriteStateAsync(CancellationToken) {#writestateasync-system-threading-cancellationtoken-b38a576e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.idurablestatemanager/methods/writestateasync-system-threading-cancellationtoken-b38a576e/)

```csharp
public abstract ValueTask WriteStateAsync(CancellationToken cancellationToken = default(CancellationToken))
```

Persists pending changes to the shared journal.

### Parameters

- `cancellationToken` (`CancellationToken`): The token used to cancel the caller's wait.

### Returns

A task representing the write acknowledgement.
