Skip to content

Commit

Permalink
Merge pull request #961 from WhitWaldo/updated-actor-csharp-quickstar…
Browse files Browse the repository at this point in the history
…t-language

Clarified actor state persistence description
  • Loading branch information
paulyuk authored Feb 11, 2024
2 parents 583e9b3 + b6a1a5e commit d718efe
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions actors/csharp/sdk/service/SmokeDetectorActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override Task OnActivateAsync()
/// </summary>
protected override Task OnDeactivateAsync()
{
// Provides Opportunity to perform optional cleanup.
// Provides opportunity to perform optional cleanup.
Console.WriteLine($"Deactivating actor id: {Id}");
return Task.CompletedTask;
}
Expand All @@ -47,9 +47,12 @@ protected override Task OnDeactivateAsync()
/// <param name="data">the user-defined MyData which will be stored into state store as "device_data" state</param>
public async Task<string> SetDataAsync(SmartDeviceData data)
{
// Data is saved to configured state store *implicitly* after each method execution by Actor's runtime.
// Data can also be saved *explicitly* by calling this.StateManager.SaveStateAsync();
// State to be saved must be DataContract serializable.
// This set state action can happen along other state changing operations in each actor method and those changes will be maintained
// in a local cache to be committed as a single transaction to the backing store when the method has completed. As such, there is
// no need to (and in fact makes your code less transactional) call `this.StateManager.SaveStateAsync()` as it will be automatically
// invoked by the actor runtime following the conclusion of this method as part of the internal `OnPostActorMethodAsyncInternal` method.

// Note also that all saved state must be DataContract serializable.
await StateManager.SetStateAsync<SmartDeviceData>(
deviceDataKey,
data);
Expand Down

0 comments on commit d718efe

Please sign in to comment.