You are developing a C# (.NET Isolated process) Durable Function orchestrator named BillingReminderOrchestrator to implement a customer billing dunning process. If a credit card payment fails, the orchestrator must pause execution and wait exactly three days before invoking an activity function to retry the payment. Which code snippet should you use inside the orchestrator to implement this delay?
- Aawait Task.Delay(TimeSpan.FromDays(3));
- Bawait context.CreateTimer(DateTime.UtcNow.AddDays(3), CancellationToken.None);
- await context.CreateTimer(context.CurrentUtcDateTime.AddDays(3), CancellationToken.None);Answer
- DThread.Sleep(TimeSpan.FromDays(3));
Answer
The correct snippet is the one that calls context.CreateTimer with context.CurrentUtcDateTime.AddDays(3).
The correct snippet uses context.CreateTimer alongside context.CurrentUtcDateTime. Durable orchestrators must be completely deterministic. Standard system-clock APIs like DateTime.UtcNow are non-deterministic during orchestration replays, so developers must use the context-provided CurrentUtcDateTime. Thread-blocking methods like Task.Delay and Thread.Sleep are also forbidden because they consume resources unnecessarily instead of scheduling a durable task in the execution history.
Step-by-Step Solution
Key Concept
Orchestrator determinism and durable timers
Estimated Time:1m 30s