C
C#3y ago
Thinker

Background service with updatable configuration

So I'm planning/trying to figure out how I'd make a Windows background service. Part of this service would be that it has a configuration file in appdata or something from which it reads certain data, but I also want to be able to update the file while the service is running and have the service recognize the updates and act accordingly. How would I do this in a decent manner? One idea I had is to watch for changes in the file using FileSystemWatcher, but idk how "modern" or reliable of an option that is.
5 Replies
becquerel
becquerel3y ago
the built-in configuration pattern has capabilities for this i believe it's called options monitor? or options snapshot? lemme google
Thinker
ThinkerOP3y ago
Does this work for files which aren't appsettings.json? Ideally I would like to have the file be a standalone JSON file in appdata or something.
becquerel
becquerel3y ago
as far as i know, you can use .AddJsonFile in the iconfigurationbuilder as many times as you want and they all get collated in appsettings.json is just a default that gets used when you have a hostbuilder or the like
Thinker
ThinkerOP3y ago
Right I haven't used the whole IConfiguration thing a whole lot so I don't know how a lot of this stuff works I'll research this more

Did you find this page helpful?