Windows Service obtains the updated value of config-Solution

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.