Skip to main content

Introduction to Activities

An Activity is a method that executes a single, well-defined action (either short or long running), which handles operations that can fail. Here are some examples:

  • Sending e-mails
  • API calls
  • Database writes
  • Network requests

An Activity involves code that is prone to failure because if it fails (let’s say the API is down), Temporal automatically retries it over and over until it succeeds or until your customized retry or timeout configuration is hit.

Here are two Activities: one for withdrawing money and one for depositing money.

using Temporalio.Activities;

public class Activities
{
[Activity]
public Task<bool> withdrawMoney(double amount)
{
// throw new Exception("Bank service temporarily unavailable");
Console.WriteLine($"Successfully withdrawn $${amount}");
return Task.FromResult(true);
}

[Activity]
public Task<bool> depositMoney(double amount)
{
Console.WriteLine($"Successfully deposited $${amount}");
return Task.FromResult(true);
}
}
3 / 9