Skip to content

Commit 4988502

Browse files
committed
pass CancellationToken to IHost.Start/Stop for ConsoleAppBuilder.Run/RunAsync
1 parent 5b188d2 commit 4988502

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

sandbox/GeneratorSandbox/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
// fail
55
//await ConsoleApp.RunAsync(args, Commands.Save);
66

7+
8+
var app = ConsoleApp.Create();
9+
10+
11+
app.Run(args, true, true, true);
12+
13+
714
// fail
8-
await ConsoleApp.RunAsync(args, async () => await Task.Delay(1000, CancellationToken.None));
15+
// await ConsoleApp.RunAsync(args, async () => await Task.Delay(1000, CancellationToken.None));
916

1017

1118
public class Commands

src/ConsoleAppFramework/ConsoleAppBaseCode.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,15 @@ public void Run(string[] args, bool startHost, bool stopHost, bool disposeServic
634634
{
635635
if (startHost && host != null)
636636
{
637-
host.StartAsync().GetAwaiter().GetResult();
637+
host.StartAsync(cancellationToken).GetAwaiter().GetResult();
638638
}
639639
RunCore(args, cancellationToken);
640640
}
641641
finally
642642
{
643643
if (stopHost && host != null)
644644
{
645-
host.StopAsync().GetAwaiter().GetResult();
645+
host.StopAsync(cancellationToken).GetAwaiter().GetResult();
646646
}
647647
if (disposeServiceProvider)
648648
{
@@ -665,7 +665,7 @@ public async Task RunAsync(string[] args, bool startHost, bool stopHost, bool di
665665
{
666666
if (startHost && host != null)
667667
{
668-
await host.StartAsync();
668+
await host.StartAsync(cancellationToken);
669669
}
670670
Task? task = null;
671671
RunAsyncCore(args, cancellationToken, ref task!);
@@ -678,7 +678,7 @@ public async Task RunAsync(string[] args, bool startHost, bool stopHost, bool di
678678
{
679679
if (stopHost && host != null)
680680
{
681-
await host.StopAsync();
681+
await host.StopAsync(cancellationToken);
682682
}
683683
if (disposeServiceProvider)
684684
{

0 commit comments

Comments
 (0)