Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 4th, 2008, 10:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
je.mason@comcast.net
__________________
-- Jeff
Reply With Quote
  #2 (permalink)  
Old July 4th, 2008, 01:53 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old July 4th, 2008, 02:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
je.mason@comcast.net
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:43 PM.


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