Solved

Configuration App settings in memory

Posted on 2015-01-26
3
69 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 32

Expert Comment

by:it_saige
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now