I faced a challenge. It is necessary to implement a service in which specified actions will be performed at certain points in time. It seems to be all simple. A service is created from a template, a timer is put, a schedule check is hung up in event handling (if there is a match, then some task is performed).

Now questions.

  1. where and how to store settings for the service?
  2. how to implement editing settings? (preferably through the form)
  3. Where can I analyze this question deeper? books, blogs, etc.

P.S. For the first time I work with services, before that I worked with the web.

    1 answer 1

    1. Settings can be stored anywhere. Traditionally, the %APPDATA%\CompanyName\ProductName folder or the HKCU\Software\CompanyName\ProductName registry branch (there are Roaming, Local, Common variants for all three - the storage location depends on what the settings affect, who should be available, and how settings should be transferred between machines).

      The format of the config is chosen by the application itself. Now JSON, XML, etc. are often used, these formats are well supported by the framework, and saving and reading settings is done in a couple of lines.

      I do not recommend using built-in tools for working with configs: they are nailed to the version, smeared over several files, do not support normal versioning, they are difficult to share and in general they are terribly limited. Write your config is a couple of lines of code and full control in the future.

    2. Service is one application, the user interface for setting is another (you can do it together, but you shouldn’t do that). You can edit the config file, and the service can subscribe to file changes.

    • '% APPDATA%' is bound to a specific user. And the service, as I understand it, will not have such a binding. Or will he know in advance which user to contact? - Aleserche
    • @Aleserche Service can be run under different accounts. If the service for the machine, that is CommonApplicationData ( C:\ProgramData ) in addition to the custom ApplicationData and LocalApplicationData . - Athari