docs
                                
                                 docs copied to clipboard
                                
                                    docs copied to clipboard
                            
                            
                            
                        Example GracePeriodManagerService, one line is not hit because of TaskCancelledException
In the example GracePeriodManagerService the line _logger.LogDebug($"GracePeriod background task is stopping."); is never hit because Task.Delay throws an TaskCancelledException. You don't see this exception, but when you add a try catch block arround it the logging line is hit.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: d49a03c0-a844-26eb-48a5-33a612dd3ead
- Version Independent ID: 0707865f-9db7-0d71-42a5-bc1a1e89680a
- Content: Implement background tasks in microservices with IHostedService and the BackgroundService class
- Content Source: docs/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice.md
- Product: dotnet-architecture
- Technology: microservices
- GitHub Login: @nishanil
- Microsoft Alias: nanil
A fixed implementation example can be found in this issue: https://github.com/dotnet/docs/issues/28251