I. Preface
In the created Windows service, you need to continuously test the service before it is officially released. In this case, you need to change the app frequently. config configuration file, but the problem arises. After the configuration file is updated, it does not take effect immediately. Instead, it obtains the value before the change. What is the cause .....
2. Unable to read the modified statement
Change the way to get config
String timevalue = configurationmanager. receivettings ["timevalue"];
This does not exist. Check the cause immediately. Why does the change not take effect immediately? Stop the service, re-compile the project, and then start the service. At this time, no problem is found. The problem is solved, but the solution is too slow.
Iii. analysis and conclusion:
After the configuration file is changed, it is not read from the physical file., You must force refresh the configuration file to read the changed configuration section information.
4. Correct writing
How to Get config after modification
private string timevalue;
Public String timevalue
{< br> Get
{< br> configurationmanager. refreshsection ("receivettings");
dtsend = configurationmanager. appsettings ["timevalue"];
return timevalue;
}< BR >}
V. Cause
Why should I add configurationmanager. refreshsection ("configurettings ");
The metadata is interpreted as follows:Refresh the naming Section so that it will be re-read from the disk the next time it is retrieved.
Vi. End
If any error occurs, please give me some advice. Thank you!
Hope this articleArticleIt can help you.
From: http://stackoverflow.com/questions/590791/do-you-have-to-restart-a-windows-service-if-you-change-the-app-config/2743097#2743097
Simultaneously published on: eniova's blog