|
-
Jun 27th, 2008, 03:36 PM
#1
Thread Starter
Fanatic Member
windows service
Hi,
I have developed a windows service which retrieves a few settings from an xml file i.e. settings.xml
There is a User Interface i.e. a winform, which allows the user to change the settings in the xml file.
The only problem is that when the user changes the xml file, then the service has to be stopped and re-started in-order for the windows service to pick up the new settings otherwise if you do not stop and re-start, then the windows service refers to the old settings even though the user has changed the xml file settings.
So, does this mean I have to develop the code to stop and re-start the service on each change of the xml file? if so, how is this done please?
Thanks
-
Jun 27th, 2008, 03:52 PM
#2
Fanatic Member
Re: windows service
You should be able to call
Code:
ConfigurationManager.RefreshSection("configuration")
to force it to reload the whole thing. You need to add a reference to System.Configuration for that line to work.
Though, this is assuming that you are trying to refresh the app.config file... Which you don't appear to be doing... What is preventing you from just reloading the file every time, or creating another thread that monitors the last updated date time of the file and refreshes it if it changes?
If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!
Show Appreciation. Rate Posts!
-
Jun 27th, 2008, 09:29 PM
#3
Re: windows service
The config file is only read once, at startup. It would be very inefficient if you had to read a file from the hard disk every time you wanted config data. What MetalKid has suggested will work because it deletes the cached version of the config data, forcing the app to re-read (and re-cache) it from disk the next time it needs that data.
The problem is, I think you'll find that that code will need to be executed inside the application whose configuration has been changed. As such, you would have to send a message to the service so it knew to refresh the appropriate config section.
A better idea would to do as you suggest and write the code to restart the service yourself. It's easily done with a ServiceController component, which can be created in code or added to a form in the designer. You create a controler for the appropriate service and then call its Stop, WaitForStatus and Start methods.
I'd be inclined to add an instance in the designer to the form that you use to edit the service's config file. If you do create an instance in code then make sure you remember to dispose it because it is a component.
-
Jun 29th, 2008, 04:03 AM
#4
Thread Starter
Fanatic Member
Re: windows service
Since I am using an xml file i.e. settings.xml and not an app.config file then do you still recommend to you ConfigurationManager?
At present I am using xmlReader and xmlWriter to read and write to it which seems to be ok so far.
It seems to me the only thing for me to do right now is to code the service stop and start. Am I right?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|