> For the complete documentation index, see [llms.txt](https://tariksavas.gitbook.io/tarsave/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tariksavas.gitbook.io/tarsave/docs/how-to-use/datapersistenceservice/autosaveasync.md).

# AutoSaveAsync

```csharp
Task AutoSaveAsync<T>(string key, T data, int intervalSeconds, 
    CancellationToken cancellationToken)
```

**Purpose:** Periodically saves data of type T asynchronously at regular intervals.&#x20;

**Parameters:**&#x20;

* key: A string to define the file path.&#x20;
* data: The data to save periodically, constrained to reference types.&#x20;
* intervalSeconds: The time interval (in seconds) between each save operation.&#x20;
* cancellationToken: A token to cancel the auto-save loop.&#x20;

**Return Value:** An async Task.

```csharp
public void AutoSave()
{
    _dataPersistenceService.AutoSaveAsync("Key", _data, 3, _cancellationToken);
}
```
