Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Fri, 04 Jul 2008 13:11:11 -0400,    group: microsoft.public.dotnet.framework        back       


Detecting changes to app.config?   
I'm trying to write some code that will detect changes in a Windows Service app's
.config file and reflect the modified appSetting entry in my code.

We have a windows Service we've written and every once in a while we need to modify a
setting in its .config file.  Right now we restart the service whenever the config
entry changes.

We'd like to have the .config update be recognized automatically.

It's easy enough to hang a FileSystemWatcher off the application's .config file to
detect a change.  In the event handler I am executing:

    ConfigurationManager.RefreshSection("appSettings")

but this seems to have no effect.  The value returned by subsequently referencing
ConfigurationManager.AppSettings(<somekey>) is the original value, not the one just
changed.  Obviously, the value has been cached.

The help for RefreshSection claims: 

"Refreshes the named section so the next time it is retrieved it will be re-read from
disk." but this doesn't appear to work.

I must not be understanding this correctly; what am I doing wrong?

Thanks for any help.


  -- Jeff
date: Fri, 04 Jul 2008 13:11:11 -0400   author:   Jeff Mason

Re: Detecting changes to app.config?   
Please do not double post - check your original post you made under 
"app.config & FileSystemWatcher".

"Jeff Mason"  wrote in message 
news:n1ms64pkojqed9ufg58s6d1c6m11fdnr52@4ax.com...
> I'm trying to write some code that will detect changes in a Windows 
> Service app's
> .config file and reflect the modified appSetting entry in my code.
>
> We have a windows Service we've written and every once in a while we need 
> to modify a
> setting in its .config file.  Right now we restart the service whenever 
> the config
> entry changes.
>
> We'd like to have the .config update be recognized automatically.
>
> It's easy enough to hang a FileSystemWatcher off the application's .config 
> file to
> detect a change.  In the event handler I am executing:
>
>    ConfigurationManager.RefreshSection("appSettings")
>
> but this seems to have no effect.  The value returned by subsequently 
> referencing
> ConfigurationManager.AppSettings(<somekey>) is the original value, not the 
> one just
> changed.  Obviously, the value has been cached.
>
> The help for RefreshSection claims:
>
> "Refreshes the named section so the next time it is retrieved it will be 
> re-read from
> disk." but this doesn't appear to work.
>
> I must not be understanding this correctly; what am I doing wrong?
>
> Thanks for any help.
>
>
>  -- Jeff
date: Sat, 5 Jul 2008 10:27:57 -0400   author:   Jeff Winn

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us