appSetting in .Config file

  • Thread starter Mats-Lennart Hansson
  • Start date

M

Mats-Lennart Hansson

Hi,
In a windows service, I have some appSettings. If I during runtime changes
one of the values, is it availabele to the service from that moment? Or do I
have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart
 
Ad

Advertisements

D

DarkSider

it depends on when you read your values?

Normally if you read in the values at startup your service will not see
the changes in the config file.

but you can program a sort of loop in your application where it checks
if changes are made to the config file, but that is not a very clean
way to handle such things in my honest opinion.

Why do need this for? Maybe i can help.
 
G

Guest

Mats,
If you use the standard app.config arrangement where the config file gets
named myService.exe.config, the configuration file is automatically read one
time at startup. For dynamic updating, you need to add a separate
filesystemwatcher and probably keep your dynamic settings in a separate
config file. A change in that would trigger re-reading the file without
having to stop the service. Actually, I use database entries and SQL Cache
Dependency as an alternative to that.
Peter
 
K

Kevin Spencer

but you can program a sort of loop in your application where it checks
if changes are made to the config file, but that is not a very clean
way to handle such things in my honest opinion.
No loop is necessary. The config files are cached when the app is started,
and when they are changed. There is no IO cost to reading directly from the
Application Configuration at any time during the lifetime of the app.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
 
K

Kevin Spencer

Which version of the Framework are you using?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
 
Ad

Advertisements

M

Mats-Lennart Hansson

Thanks, that's exactly what I was looking for. Unfortunately, the
functionality wasn't what I hoped for. But hey, that's life :)

Thanks to all that responded.

/Mats-Lennart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top