2556

Windows Services - Is it advisable to update its config file while running?

Question:

As per my title, I would like to clarify: Is it advisable to update the config file while a .Net windows service is running?

What would be its implications, if this is possible?

Thank you.

Cheers, Ann

Answer1:

There are other excellent answers here, but what are you asking? Are you asking about a service that <strong>you</strong> are writing? Or about someone else's Service.

If it is about a service you are going to write, then no, there is no automatic reload of the .config file when it is changed. You will either have to:

<ol><li>Restart the service to see the changes.</li> <li>Write your service to use a FileSystemWatcher to see if the config file has been changed and then decide what you want to do with any or all the values that have changed.</li> </ol>

If it is about someone else's service, you will need to ask them how it works based upon the above description.

Answer2:

This should have no effect on the running program. Configuration is loaded during application startup. If you want those new settings to take effect, you need to restart the service.

<strong>Edit</strong>: More to the point of answering your question: When one creates a Windows service in .NET (I'm using Visual Studio 2010), an application configuration file is not created with it by default. By adding a New Item / Application Configuration File (App.config), you are creating a file that gets loaded at the start of the service. As commented below, there is no guarantee that it isn't being monitored during run time (unless you're the creator and you know that's the case), but this is not the common practice for App.config.

Under these standard conditions, it is advisable to make the changes, while running, after backing up the working copy of the config file. Then restart the service. If you broke it, revert back to your working copy.

Answer3:

You can do it but it comes with a cost, do you want your service poll to know if there is any changes to the config file while it is running ? Generally, I would not recommend polling for the content changes in the config file.

Recommend

  • How to prevent copy, paste and delete file from the determined directory [closed]
  • Pull any machine specific information from Windows audit log?
  • Attach event handler to be called only once
  • Keep a Windows Service running without a timer
  • Firebase Authentication Javascript: setCookie for pending Credential for redirect
  • Cannot use Turkish characters with Entity Framework
  • python - terminate child process when script invoked from bash
  • Entity Framework Core 1.0.1 add-migration
  • update record in database using jdatabase
  • How to format data from string variable
  • How do you SELECT several columns with one distinct column
  • How to select table rows/complete table?
  • Multicolor tooltip in Qt
  • Avoid registering duplicate broadcast receivers in Android
  • Deploying a CodeRush plugin from the Community Site
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • QLPreviewController hide print button in ios6
  • Use of this Javascript
  • C++ Partial template specialization - design simplification
  • Email format validation in mvc3 view
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Uncaught Error: Could not find module `ember-load-initializers`
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Sony Xperia Z Tablet not found by adb
  • How to add date and time under each post in guestbook in google app engine
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Excel - Autoshape get it's name from cell (value)
  • ILMerge & Keep Assembly Name
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Convert array of 8 bytes to signed long in C++
  • Large data - storage and query
  • How to get next/previous record number?
  • WOWZA + RTMP + HTML5 Playback?
  • Python: how to group similar lists together in a list of lists?
  • Understanding cpu registers
  • coudnt use logback because of log4j
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices