Troubleshoot issues that must be restarted after the Windows service modifies a configuration file

Source: Internet
Author: User

Original address: http://www.cnblogs.com/jeffwongishandsome/archive/2011/04/24/2026381.html Workaround: Refresh the file before reading the configuration fileRefreshes the named section, which is re-read from disk The next time it is retrieved. Configurationmanager.refreshsection ("appSettings"); recordCount = Math.Abs (int. Parse (configurationmanager.appsettings["RecordCount")); analysis:. NET read configuration file is generally read from the cache, after modifying the configuration file does not affect the value in the cache, and the read before the refresh file. NET reads the profile value from the hard disk file rather than from the cache Performance Comparison:Preconditions : Six configuration items in app. Config  read 10,000 times after calling Refreshsection:var sw = new Stopwatch (); SW. Start (); for (int i = 0; i < 10000; i++) {configurationmanager.refreshsection ("appSettings");Object value = configurationmanager.appsettings["Redisserver"];}timespan ts = sw. Elapsed;string elapsedtime = String.Format ("{0:00}: {1:00}: minute {2:00}: seconds: {3:00}: milliseconds",ts. Hours, TS. Minutes, TS. Seconds,TS.MILLISECONDS/10);//00: Time 00: minutes 07: seconds: 43: Millisecondsstring KK = ElapsedTime;read 10,000 times after not calling Refreshsection:
var sw = new Stopwatch (); SW. Start (); for (int i = 0; i < 10000; i++) {Object value = configurationmanager.appsettings["Redisserver"];} TimeSpan ts = sw. Elapsed;string elapsedtime = String.Format ("{0:00}: {1:00}: minute {2:00}: seconds: {3:00}: milliseconds",ts. Hours, TS. Minutes, TS. Seconds,TS.MILLISECONDS/10);//00: Time 00: minutes 00: seconds: 01: Millisecondsstring KK = ElapsedTime; Conclusion:Using Refreshsection to refresh the file before reading has a significant impact on performance

Troubleshoot issues that must be restarted after the Windows service modifies a configuration file

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.