mirror of
https://github.com/temporalio/skill-temporal-developer.git
synced 2026-09-14 13:52:58 +08:00
Simplify .NET worker execution example
This commit is contained in:
@@ -59,20 +59,13 @@ using Temporalio.Worker;
|
||||
|
||||
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
|
||||
|
||||
using var tokenSource = new CancellationTokenSource();
|
||||
Console.CancelKeyPress += (_, eventArgs) =>
|
||||
{
|
||||
tokenSource.Cancel();
|
||||
eventArgs.Cancel = true;
|
||||
};
|
||||
|
||||
using var worker = new TemporalWorker(
|
||||
client,
|
||||
new TemporalWorkerOptions("my-task-queue")
|
||||
.AddWorkflow<GreetingWorkflow>()
|
||||
.AddAllActivities(new MyActivities()));
|
||||
|
||||
await worker.ExecuteAsync(tokenSource.Token);
|
||||
await worker.ExecuteAsync(() => Task.Delay(Timeout.Infinite));
|
||||
```
|
||||
|
||||
**Start the dev server:** Start `temporal server start-dev` in the background.
|
||||
|
||||
Reference in New Issue
Block a user