Skip to content

Commit 4aa9fc6

Browse files
resolve comments
1 parent bb54c57 commit 4aa9fc6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-background-service.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
7979
// Load all keys that start with `TestApp:`.
8080
.Select("TestApp:*")
8181
// Configure to reload the key 'TestApp:Settings:Message' if it is modified.
82-
.ConfigureRefresh(refresh =>
82+
.ConfigureRefresh(refreshOptions =>
8383
{
84-
refresh.Register("TestApp:Settings:Message")
85-
.SetCacheExpiration(TimeSpan.FromSeconds(5));
84+
refreshOptions.Register("TestApp:Settings:Message");
8685
});
8786
8887
// Register the refresher so that the Worker service can consume it through DI
@@ -92,7 +91,7 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
9291
builder.Services.AddFeatureManagement();
9392
```
9493
95-
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `Register` method has an optional boolean parameter `refreshAll` that can be used to indicate whether all configuration values should be refreshed if the registered key changes. In this example, only the key *TestApp:Settings:Message* will be refreshed. The `SetCacheExpiration` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 5 seconds instead for demonstration purposes.
94+
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `Register` method has an optional boolean parameter `refreshAll` that can be used to indicate whether all configuration values should be refreshed if the registered key changes. In this example, only the key *TestApp:Settings:Message* will be refreshed. All settings registered for refresh have a default cache expiration of 30 seconds before a new refresh is attempted. It can be updated by calling the `AzureAppConfigurationRefreshOptions.SetCacheExpiration` method.
9695
9796
1. Open *Worker.cs*. Inject `IConfiguration` and `IConfigurationRefresher` to the `Worker` service and log the configuration data from App Configuration.
9897
@@ -116,7 +115,8 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
116115
{
117116
if (_refresher != null)
118117
{
119-
await _refresher.TryRefreshAsync(stoppingToken);
118+
// Intentionally not await TryRefreshAsync to avoid blocking the execution.
119+
_refresher.TryRefreshAsync(stoppingToken);
120120
}
121121
122122
if (_logger.IsEnabled(LogLevel.Information))
@@ -129,7 +129,7 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
129129
}
130130
```
131131
132-
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method from the interface `IConfigurationRefresher` to trigger a refresh. This design is to avoid phantom requests sent to App Configuration even when your application is idle. You can include the `TryRefreshAsync` call where you consider your application active. For example, it can be when you process an incoming message, an order, or an iteration of a complex task. It can also be in a timer if your application is active all the time. In this example, you call `TryRefreshAsync` when you press the Enter key. Note that, even if the call `TryRefreshAsync` fails for any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured cache expiration time has passed and the `TryRefreshAsync` call is triggered by your application activity again. Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal, even if it's called frequently.
132+
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method from the interface `IConfigurationRefresher` to trigger a refresh. This design is to avoid phantom requests sent to App Configuration even when your application is idle. You can include the `TryRefreshAsync` call where you consider your application active. For example, it can be when you process an incoming message, an order, or an iteration of a complex task. It can also be in a timer if your application is active all the time. In this example, you call `TryRefreshAsync` every time the background service is executed. Note that, even if the call `TryRefreshAsync` fails for any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured cache expiration time has passed and the `TryRefreshAsync` call is triggered by your application activity again. Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal, even if it's called frequently.
133133
134134
## Build and run the app locally
135135
@@ -193,7 +193,7 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
193193
|----------------------------|-----------------------------------------------|
194194
| *TestApp:Settings:Message* | *Data from Azure App Configuration - Updated* |
195195
196-
1. Wait for about 5 seconds. You should see the console outputs changed.
196+
1. Wait for about 30 seconds. You should see the console outputs changed.
197197
198198
![Background service refresh](./media/dotnet-background-service-refresh.png)
199199

0 commit comments

Comments
 (0)