Skip to content

Commit 1826009

Browse files
authored
Simplify WindowsBackgroundService (#26311)
No need in `try-catch` for OperationCanceledException. See dotnet/aspnetcore#35127
1 parent 3de8e22 commit 1826009

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

docs/core/extensions/snippets/workers/windows-service/WindowsBackgroundService.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2020
{
2121
while (!stoppingToken.IsCancellationRequested)
2222
{
23-
try
24-
{
25-
string joke = await _jokeService.GetJokeAsync();
26-
_logger.LogWarning(joke);
23+
string joke = await _jokeService.GetJokeAsync();
24+
_logger.LogWarning(joke);
2725

28-
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
29-
}
30-
catch (OperationCanceledException)
31-
{
32-
break;
33-
}
26+
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
3427
}
3528
}
3629
}

0 commit comments

Comments
 (0)