Piotr Stapp
Piotr Stapp

Reputation: 19830

How to discover that appsettings changed in C#?

Is there a way to (event will be the best option), which will notice my code that app settings changed?

Exactly I am trying to implement a windows service in which administrator should change behavior "online" without restarting service.

I was thinking about FileSystemWatcher, but in this option I will have to hardcode path and name to config file, so maybe there is other way of doing this?

UPDATE

Below answers suggests to use AppDomain.CurrentDomain.SetupInformation.ConfigurationFile but this option will not work if I have external config file defined like this:

<configuration>
  <appSettings configSource="appsettings.config"/>
</configuration>

Upvotes: 3

Views: 2164

Answers (2)

Mikael &#214;stberg
Mikael &#214;stberg

Reputation: 17156

You can use the FileSystemWatcher with the path from this statement:

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

No need for hard coded paths.

Upvotes: 2

Bassam Alugili
Bassam Alugili

Reputation: 17003

maybe by using timer in a background thread and checking each 5 seconds the config file checksum If changed than fire config changed event.

Upvotes: 0

Related Questions