How can I watch the user.config file and reload the settings when it changes?

后端 未结 3 797
深忆病人
深忆病人 2021-02-11 00:30

I have a situation where I am running multiple instances of my WPF application. I want the instances to share the same user.config file. Currently, whichever instance writes t

3条回答
  •  梦毁少年i
    2021-02-11 01:08

    I found it. The following code will return the path to the user.config file. You need to add a reference to System.Configuration.dll

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
    string path = config.FilePath;
    

    Now I can use a FileSystemWatcher to get notified when the file changes.

提交回复
热议问题