<p>I plan to be storing all my config settings in my application's app.config section (using the <code>ConfigurationManager.AppSettings</code> class). As the user changes settings using the app's UI (clicking checkboxes, choosing radio buttons, etc.), I plan to be writing those changes out to the <code>AppSettings</code>. At the same time, while the program is running I plan to be accessing the <code>AppSettings</code> constantly from a process that will be constantly processing data. Changes to settings via the UI need to affect the data processing in real-time, which is why the process will be accessing the <code>AppSettings</code> constantly.</p>

<p>Is this a good idea with regard to performance? Using <code>AppSettings</code> is supposed to be "the right way" to store and access configuration settings when writing .Net apps, but I worry that this method wasn't intended for a constant load (at least in terms of settings being constantly read).</p>

<p>If anyone has experience with this, I would greatly appreciate the input.</p>

<p><strong>Update:</strong> I should probably clarify a few points.</p>

<p>This is not a web application, so connecting a database to the application might be overkill simply for storing configuration settings. This is a Windows Forms application.</p>

<p>According to the MSDN documention, the <code>ConfigurationManager</code> is for storing not just application level settings, but user settings as well. (Especially important if, for instance, the application is installed as a partial-trust application.)</p>

<p><strong>Update 2:</strong> I accepted lomaxx's answer because <code>Properties</code> does indeed look like a good solution, without having to add any additional layers to my application (such as a database). When using Properties, it already does all the caching that others suggested. This means any changes and subsequent reads are all done in memory, making it extremely fast. Properties only writes the changes to disk when you explicitly tell it to. This means I can make changes to the config settings on-the-fly at run time and then only do a final save out to disk when the program exits.</p>

<p>Just to verify it would actually be able to handle the load I need, I did some testing on my laptop and was able to do 750,000 reads and 7,500 writes per second using Properties. That is so far above and beyond what my application will <em>ever</em> even come close to needing that I feel quite safe in using Properties without impacting performance.</p>

[{'answer_id': 4175, 'author': 'Brandon Wood', 'author_id': 423, 'author_profile': 'https://Stackoverflow.com/users/423', 'pm_score': 1, 'selected': False, 'text': "<p>Someone correct me if I'm wrong, but I don't think that AppSettings is typically meant to be used for these type of configuration settings.  Normally you would only put in settings that remain fairly static (database connection strings, file paths, etc.).  If you want to store customizable user settings, it would be better to create a separate preferences file, or ideally store those settings in a database.</p>\n"}, {'answer_id': 4178, 'author': 'Shawn', 'author_id': 26, 'author_profile': 'https://Stackoverflow.com/users/26', 'pm_score': 0, 'selected': False, 'text': "<p>Could I ask why you're not saving the user's settings in a database?</p>\n\n<p>Generally, I save application settings that are changed very infrequently in the appSettings section (the default email address error logs are sent to, the number of minutes after which you are automatically logged out, etc.) The scope of this really is at the application, not at the user, and is generally used for deployment settings.</p>\n"}, {'answer_id': 4180, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 0, 'selected': False, 'text': '<p>one thing I would look at doing is caching the appsettings on a read, then flushing the settings from the cache on the write which should minimize the amount of actual load the server has to deal with for processing the appSettings.</p>\n\n<p>Also, if possible, look at breaking the appSettings up into <a href="http://www.copernic.com/en/products/desktop-search/whats-new-15.html" rel="nofollow noreferrer">configSections</a> so you can read write and cache related settings.</p>\n\n<p>Having said all that, I would seriously consider looking at storing these values in a database as you seem to actually be storing <b>user preferences</b>, and not application settings.</p>\n'}, {'answer_id': 4214, 'author': 'Shawn', 'author_id': 26, 'author_profile': 'https://Stackoverflow.com/users/26', 'pm_score': 2, 'selected': False, 'text': '<p>Check out SQLite, it seems like a good option for this particular scenario.</p>\n'}, {'answer_id': 4217, 'author': 'Kevin Sheffield', 'author_id': 590, 'author_profile': 'https://Stackoverflow.com/users/590', 'pm_score': 1, 'selected': False, 'text': '<p>I would not use config files for storing user data. Use a db.</p>\n'}, {'answer_id': 4220, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 4, 'selected': True, 'text': '<p>since you\'re using a winforms app, if it\'s in .net 2.0 there\'s actually a user settings system (called Properties) that is designed for this purpose. <a href="https://learn.microsoft.com/en-us/previous-versions/aa730869%28v=vs.80%29" rel="nofollow noreferrer">This article on MSDN</a> has a pretty good introduction into this</p>\n<p>If you\'re still worried about performance then take a look at <a href="https://web.archive.org/web/20080918011815/http://www.microsoft.com:80/sql/editions/compact/default.mspx" rel="nofollow noreferrer">SQL Compact Edition</a> which is similar to SQLite but is the Microsoft offering which I\'ve found plays very nicely with winforms and there\'s even the ability to <a href="https://web.archive.org/web/20181015183404/http://geekswithblogs.net:80/steveclements/archive/2007/11/13/linq-to-sql.compact.aspx" rel="nofollow noreferrer">make it work with Linq</a></p>\n'}, {'answer_id': 4233, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 2, 'selected': False, 'text': "<p>Dylan,</p>\n\n<p>Don't use the application config file for this purpose, use a SQL DB (SQLite, MySQL, MSSQL, whatever) because you'll have to worry less about concurrency issues during reads and writes to the config file. </p>\n\n<p>You'll also have better flexibility in the type of data you want to store. The appSettings section is just a key/value list which you may outgrow as time passes and as the app matures. You could use custom config sections but then you're into a new problem area when it comes to the design.</p>\n"}, {'answer_id': 4250, 'author': 'Seibar', 'author_id': 357, 'author_profile': 'https://Stackoverflow.com/users/357', 'pm_score': 2, 'selected': False, 'text': "<p>The appSettings isn't really meant for what you are trying to do.</p>\n\n<p>When your .NET application starts, it reads in the app.config file, and caches its contents in memory. For that reason, after you write to the app.config file, you'll have to somehow force the runtime to re-parse the app.config file so it can cache the settings again. This is unnecessary </p>\n\n<p>The <strong>best approach</strong> would be to use a database to store your configuration settings.</p>\n\n<p>Barring the use of a database, you could easily setup an external XML configuration file. When your application starts, you could cache its contents in a NameValueCollection object or HashTable object. As you change/add settings, you would do it to that cached copy. When your application shuts down, or at an appropriate time interval, you can write the cache contents back out to file.</p>\n"}]
['https://Stackoverflow.com/questions/4157', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/551/']