Solved

Configuration App settings in memory

Posted on 2015-01-26
3
77 Views
Last Modified: 2015-01-27
I have an application where the configuration values are read from various classes some of which are static.

How can I ensure that when I get the values from the appSettings the application does not need to reopen the app.config file but uses these from memory.

I had thought of creating a class that I can pass around that just loads the settings into say a List<String>.

Is there a standard way of holding the appSettings in memory and so ensuring better performance?
0
Comment
Question by:jetbet
  • 2
3 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40571526
The ConfigurationManager class does load the application settings in memory.

This is why Application Settings that are changed while a program is running do not take affect until the application is restarted (or you explicitly call the RefreshSection method).

You can refer to this blog post for more information: http://www.c-sharpcorner.com/UploadFile/akkiraju/refreshing-the-net-application-to-read-modified-configurati/

-saige-
0
 
LVL 40
ID: 40571851
I have to partially contradict it_saige.

Yes, the application settings are loaded into memory. In fact, it takes the role of the class that you want to create, so I do not see the need for it. Change a setting, and it is changed for the life of the current run of the application.

However, the settings do take effect in the current run of the application as soon as you change them. Change a setting, read it back, it it has the new value.

It's their persistence between runs of the application that could be in question if you do not Save them back to app.config before exiting the application.
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40572835
Let me qualify my statement for clarity.  Changing the AppSetting by editing the XML file directly, does not affect the setting while the application is running (this is what the blog post above illustrates).

However, James is correct, if you change the setting that is loaded into memory, then the setting change takes affect immediately.  Also, as James points out, you do need to save the setting(s) back to the XML file when you change them.

-saige-
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question