views:

784

answers:

7

Do you have to restart a windows service if you change the app.config?

+10  A: 

Yes, you do.

Randolpho
+4  A: 

Yes.

Presumably you mean the appname.exe.config file?

Mitch Wheat
+7  A: 

No, you don't have to. But if you want for changes in app.config to take effect, you might need to restart it. Or you might want to implement a custom configuration file watcher mechanism which would alter services' settings on the fly.

Anton Gogolev
" if you want for changes in app.config to take effect," - I think that is implicit in the question!
Mitch Wheat
Great, just when I'm out of rubber chickens.
Gamecat
@Gamecat: free range?
Mitch Wheat
+1  A: 

This goes way out of the scope of the question, but I would guess you want to make changes only in some "application-specific" section (appSettings, etc.).

You are better off writing your own config section handler, which monitors it's own config file - the approach nlog uses. Check the section "Automatic reconfiguration".

Sunny
A: 

Usually yes. However you could write a windows service that would put a file monitor on the configuration file and sense a modification and apply it without the need to restart.

For example the Log4Net logging framework offers such a mechanism for its configuration file.

Andrei Rinea
+1  A: 

I've used this before. Essentially this reloads the specified section before retrieving the value. Quite possibly less efficient than a config file watcher that refreshes on demand, but certainly effective used carefully.

  ConfigurationManager.RefreshSection("appSettings")
  sValue = ConfigurationManager.AppSettings(name)
jdigaetano
A: 

ConfigurationManager.RefreshSection("appSettings") sValue = ConfigurationManager.AppSettings(name)

very good

thanks

e6wa