Keep settings in sync between forms application and windows service (or any n-tier, really)

前端 未结 4 729
太阳男子
太阳男子 2021-01-03 04:25

I have a Windows Service that performs a number of periodic activities, and I want to change the settings of this service from a Windows Forms app. I\'m not sure, though, ab

4条回答
  •  时光取名叫无心
    2021-01-03 05:08

    Usually services that perform a 'polling operation' (i.e. sync files) have enough lag time in their poll interval that you can just as easily re-read all settings each loop, or even as needed.

    If your service is more along the lines of a SOA back-end, then the changes may affect settings that are generally only used once during a service's lifetime. If this is your type of application, then the option #2 you describe above is the most reliable. I can't say I care much for Paul's implementation as polling a file like that will yield unreliable results. I would recommend using a globally named wait handle to signal your process for changes. I'm sure you can find an example here on SO. If you don't want to do that then you could poll for the configuration file's last-modified time changing.

    Overall my preference is for the first approach using the registry for storage. Write all your settings in discrete values in a registry hive and read them on-demand in your service. It's faster than you might think and easy to implement on both front and back-end.

提交回复
热议问题