Wrox Programmer Forums
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 4th, 2008, 10:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default 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.

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.

What am I doing wrong?

Thanks for any help.



Jeff Mason
[email protected]
__________________
-- Jeff
 
Old July 4th, 2008, 01:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

To what extent have you debugged the FileWatcher behavior? If I recall correctly you set a file watcher to watch a directory and it will give you info about what files system entries (both dirs and files) changed. Have you analyzed this output to see if it is actually detecting the right change(s)?

-Peter
compiledthoughts.com
 
Old July 4th, 2008, 02:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

I have verified that the FileSystemWatcher is doing what I want it to do. The Changed event is in fact firing when I, for example, modify the .config file via notepad.

In the Changed event handler, I execute:

      ConfigurationManager.RefreshSection("appSettings")

but subsequent access to an appSettings key gives me the original (presumably cached) value. I was expecting that RefreshSection would invalidate or otherwise clear the cache so the new modified value gets picked up, but that doesn't seem to be happening. After the event fires, subsequent access via:

      ConfigurationManager.AppSettings(<somekey>)

returns the original value, before the update.

FileSystemWatcher isn't my problem, I think. ConfigurationManager apparently is...

Jeff Mason
[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
web.config <compilation> <assemblies> Jophie BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 10th, 2008 12:04 PM
Web.Config xmlns for <configuration> mhardiman BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 9th, 2006 11:08 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 05:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.