Skip to content

Commit 386ec7f

Browse files
authored
Simplify the using statement (#18317)
1 parent fbecab1 commit 386ec7f

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

  • aspnetcore/fundamentals/host/hosted-services/samples/3.x/BackgroundTasksSample

aspnetcore/fundamentals/host/hosted-services/samples/3.x/BackgroundTasksSample/Program.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Program
99
{
1010
public static async Task Main(string[] args)
1111
{
12-
using (var host = Host.CreateDefaultBuilder(args)
12+
using var host = Host.CreateDefaultBuilder(args)
1313
.ConfigureServices((hostContext, services) =>
1414
{
1515
#region snippet3
@@ -27,20 +27,16 @@ public static async Task Main(string[] args)
2727
services.AddScoped<IScopedProcessingService, ScopedProcessingService>();
2828
#endregion
2929
})
30-
.Build())
31-
{
32-
// Start the host
33-
await host.StartAsync();
30+
.Build();
3431

35-
// Monitor for new background queue work items
36-
#region snippet4
37-
var monitorLoop = host.Services.GetRequiredService<MonitorLoop>();
38-
monitorLoop.StartMonitorLoop();
39-
#endregion
32+
await host.StartAsync();
4033

41-
// Wait for the host to shutdown
42-
await host.WaitForShutdownAsync();
43-
}
34+
#region snippet4
35+
var monitorLoop = host.Services.GetRequiredService<MonitorLoop>();
36+
monitorLoop.StartMonitorLoop();
37+
#endregion
38+
39+
await host.WaitForShutdownAsync();
4440
}
4541
}
4642
}

0 commit comments

Comments
 (0)