Windows services 使用app.config确定公共配置文件

Windows services 使用app.config确定公共配置文件,windows-services,app-config,Windows Services,App Config,我正在使用app.config执行windows服务,其中有一个部分用于检索另一个文件中的公共配置。使用 AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "filepath\\file"); 对我有用,但使用 string appconfig = ConfigurationManager.AppSettings["CommonAppSetting"]; AppDomain.CurrentDomain.SetData("APP_CONFIG

我正在使用app.config执行windows服务,其中有一个部分用于检索另一个文件中的公共配置。使用

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "filepath\\file"); 
对我有用,但使用

string appconfig = ConfigurationManager.AppSettings["CommonAppSetting"];
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", appconfig);
没有。它来自windows服务的app.config,而不是普通配置


我做错了什么,或者还有其他更好的方法吗?

您需要重置
ConfigurationManager
中的一些变量(ClientConfigPath),以便它刷新其值。这些可以在以下公认的答案中看到(包括完成此项腿部工作的代码)