From 32ab503d159f7cce47d2a48e5540cfb20a4749e2 Mon Sep 17 00:00:00 2001 From: Ryan Lettieri Date: Tue, 28 Nov 2023 16:41:44 -0700 Subject: [PATCH] Adding in ability to cancel workflow example Signed-off-by: Ryan Lettieri --- examples/Workflow/WorkflowConsoleApp/Program.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/Workflow/WorkflowConsoleApp/Program.cs b/examples/Workflow/WorkflowConsoleApp/Program.cs index 9aae2427e..9f70e5025 100644 --- a/examples/Workflow/WorkflowConsoleApp/Program.cs +++ b/examples/Workflow/WorkflowConsoleApp/Program.cs @@ -81,7 +81,14 @@ // Start the input loop using (daprClient) { - while (true) + bool quit = false; + Console.CancelKeyPress += delegate + { + quit = true; + Console.WriteLine("Shutting down the example."); + }; + + while (!quit) { // Get the name of the item to order and make sure we have inventory string items = string.Join(", ", baseInventory.Select(i => i.Name)); @@ -138,7 +145,7 @@ await daprClient.StartWorkflowAsync( Console.WriteLine($"{state.WorkflowName} (ID = {orderId}) started successfully with {state.ReadInputAs()}"); // Wait for the workflow to complete - while (true) + while (!quit) { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); try