3

I have have running windows service that is using it's app.config for getting some important values. Now I would like to provide a different GUI application that provide a way to change these important values and save it to the same app.config.

My question is this: will it be possible to share this app.config between the projects by using "Add as a link" and if I then use my GUI application and change some values, will this be reflected in the windows service?

EDIT: If this works, then perhaps someone also know the details of how the linking works in a more technical view?

Marthin
  • 6,413
  • 15
  • 58
  • 95
  • If you need to change the settings in your config so often that it's worth writing a GUI application for it, why not refactor those values into the DB? It would also mean that you don't care about where each application is stored. – rie819 Feb 08 '12 at 12:42
  • The reason right now is that in my windows service i'm thinking of listening to FileChangeEvent from windows. So once the file values has changed and then my service can react and take appropiate actions. But you may be totaly right and this will probably end up in the DB in the end =) – Marthin Feb 08 '12 at 14:27

3 Answers3

4

Both the projects can share the same app.config. Not sure about linking, but you can have same structure and values in two different config, but when deploying it, deploy it in same folder as windows service.

Now regarding updating the values of app.config, they will not get reflected in windows service, if win service is running. You will need to restart the windows service for this. Because app settings are cached in memory, and loaded in memory when app starts. You can use ConfigurationManager.RefreshSection to refresh the loaded config in memory. You can read about it on MSDN. You will have have to do this in your windows service.

Hope this info helps you.

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
0

If your GUI application doesn't rely on any values from the app.config (i.e. just edit it) and you plan to launch your GUI application from the same folder as your service you could just open it like any (text/xml)file (maybe even include a file open dialogue).

Depending on your VCS you can "link" the app.config from your windows service project to your GUI application project - I, personally using SubVersion would do this with Externals.

Community
  • 1
  • 1
Filburt
  • 17,626
  • 12
  • 64
  • 115
0

generally speaking, every third called app from the 'windows service' uses configuration files deployed by windows application project. Thanks to that, current configuration depends on the starting project (could be wf, wpf, web...).

just remember to set the additional config files to be deployed with the application

Properties -> Copy to output folder -> Copy Always This behavior is quite easy to understand if you look into the deployed application directory. It contains all the projects' as dlls and all the other files configured to be copied to the final folder. By default each project has the same access to these files as they are all in the same location.

But be carreful about what Amar Palsapure says about how appconfig data are caching.

user852194
  • 165
  • 1
  • 2
  • 12