From fba5bbc13e238dfe7df968939f2a4cb8176d52d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20dos=20Santos=20Portela?= Date: Tue, 26 Mar 2019 17:38:11 +0000 Subject: [PATCH] Make StartupTaskCompleted volatile (#10897) --- aspnetcore/host-and-deploy/health-checks.md | 4 ++-- .../HealthChecksSample/StartupHostedServiceHealthCheck.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aspnetcore/host-and-deploy/health-checks.md b/aspnetcore/host-and-deploy/health-checks.md index d076aa0307..208e13a653 100644 --- a/aspnetcore/host-and-deploy/health-checks.md +++ b/aspnetcore/host-and-deploy/health-checks.md @@ -5,7 +5,7 @@ description: Learn how to set up health checks for ASP.NET Core infrastructure, monikerRange: '>= aspnetcore-2.2' ms.author: riande ms.custom: mvc -ms.date: 02/13/2019 +ms.date: 03/11/2019 uid: host-and-deploy/health-checks --- # Health checks in ASP.NET Core @@ -387,7 +387,7 @@ The readiness check usually performs a more extensive and time-consuming set of The sample app contains a health check to report the completion of long-running startup task in a [Hosted Service](xref:fundamentals/host/hosted-services). The `StartupHostedServiceHealthCheck` exposes a property, `StartupTaskCompleted`, that the hosted service can set to `true` when its long-running task is finished (*StartupHostedServiceHealthCheck.cs*): -[!code-csharp[](health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs?name=snippet1&highlight=5)] +[!code-csharp[](health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs?name=snippet1&highlight=7-11)] The long-running background task is started by a [Hosted Service](xref:fundamentals/host/hosted-services) (*Services/StartupHostedService*). At the conclusion of the task, `StartupHostedServiceHealthCheck.StartupTaskCompleted` is set to `true`: diff --git a/aspnetcore/host-and-deploy/health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs b/aspnetcore/host-and-deploy/health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs index a693b1fdfb..2394d23057 100644 --- a/aspnetcore/host-and-deploy/health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs +++ b/aspnetcore/host-and-deploy/health-checks/samples/2.x/HealthChecksSample/StartupHostedServiceHealthCheck.cs @@ -11,9 +11,15 @@ namespace SampleApp #region snippet1 public class StartupHostedServiceHealthCheck : IHealthCheck { + private volatile bool _startupTaskCompleted = false; + public string Name => "slow_dependency_check"; - public bool StartupTaskCompleted { get; set; } = false; + public bool StartupTaskCompleted + { + get => _startupTaskCompleted; + set => _startupTaskCompleted = value; + } public Task CheckHealthAsync( HealthCheckContext context,