Skip to content

Commit d9a66b7

Browse files
committed
no use hosting
1 parent 39935d6 commit d9a66b7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/ConsoleAppFramework/ConsoleAppBaseCode.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,17 @@ public void Run(string[] args, bool startHost, bool stopHost, bool disposeServic
632632
Microsoft.Extensions.Hosting.IHost? host = ConsoleApp.ServiceProvider?.GetService(typeof(Microsoft.Extensions.Hosting.IHost)) as Microsoft.Extensions.Hosting.IHost;
633633
try
634634
{
635-
if (startHost)
635+
if (startHost && host != null)
636636
{
637-
host?.StartAsync().GetAwaiter().GetResult();
637+
host.StartAsync().GetAwaiter().GetResult();
638638
}
639639
RunCore(args, cancellationToken);
640640
}
641641
finally
642642
{
643-
if (stopHost)
643+
if (stopHost && host != null)
644644
{
645-
host?.StopAsync().GetAwaiter().GetResult();
645+
host.StopAsync().GetAwaiter().GetResult();
646646
}
647647
if (disposeServiceProvider)
648648
{
@@ -663,9 +663,9 @@ public async Task RunAsync(string[] args, bool startHost, bool stopHost, bool di
663663
Microsoft.Extensions.Hosting.IHost? host = ConsoleApp.ServiceProvider?.GetService(typeof(Microsoft.Extensions.Hosting.IHost)) as Microsoft.Extensions.Hosting.IHost;
664664
try
665665
{
666-
if (startHost)
666+
if (startHost && host != null)
667667
{
668-
await host?.StartAsync();
668+
await host.StartAsync();
669669
}
670670
Task? task = null;
671671
RunAsyncCore(args, cancellationToken, ref task!);
@@ -676,9 +676,9 @@ public async Task RunAsync(string[] args, bool startHost, bool stopHost, bool di
676676
}
677677
finally
678678
{
679-
if (stopHost)
679+
if (stopHost && host != null)
680680
{
681-
await host?.StopAsync();
681+
await host.StopAsync();
682682
}
683683
if (disposeServiceProvider)
684684
{

0 commit comments

Comments
 (0)