Solved

Configuration App settings in memory

Posted on 2015-01-26
3
79 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

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 34

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
Excel Web Add-in Where is Visual Basic used 9 69
Put File 6 34
Convert a string to date 4 39
.NET Core supports which cell phone platforms? 3 32
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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