Skip to content

Commit

Permalink
Adding in ability to cancel workflow example
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
  • Loading branch information
RyanLettieri committed Nov 28, 2023
1 parent 71064cf commit 32ab503
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/Workflow/WorkflowConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -138,7 +145,7 @@ await daprClient.StartWorkflowAsync(
Console.WriteLine($"{state.WorkflowName} (ID = {orderId}) started successfully with {state.ReadInputAs<OrderPayload>()}");

// Wait for the workflow to complete
while (true)
while (!quit)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
try
Expand Down

0 comments on commit 32ab503

Please sign in to comment.