473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ConfigurationSettings.AppSettings["foo"]

Could someone provide me with details or a link on how the line of code
executes underneath the hood? Assume it's executed in an ASP.NET
application.

string blah = ConfigurationSettings.AppSettings["foo"]

Once your application has called for the "foo" key once, how expensive is to
call the same line again? My gut tells me that the CLR likely stores these
values in memory in a string dictionary or similar. Looking up the value
requires the potentially sorted collection to "lookup" the key again and
retrieve the value hopefully leveraging a b-tree or similar in the sorted
collection.

Perhaps it works a different way? Just curious. Thanks.

Mark
Jan 11 '07 #1
8 2614
Hi,

"Mark" <ma*********@nospam.nospamwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
| Could someone provide me with details or a link on how the line of code
| executes underneath the hood? Assume it's executed in an ASP.NET
| application.
|
| string blah = ConfigurationSettings.AppSettings["foo"]
|
| Once your application has called for the "foo" key once, how expensive is
to
| call the same line again?

Not much, only a lookup in some struct in memory ( hashtable, etc). At some
moment the file needs to be loaded. IMO (but I have no fact to prove it) it
happens when the application loads.

Also remember that even as the file remains closed the engine keeps an eye
on it (probably using a FileSystemWatcher) to detect change, if it does it
reload the entire app

--
Ignacio Machin
machin AT laceupsolutions com
Jan 11 '07 #2

It loads the first time ConfigurationSettings.AppSettings is called,
not necessarily on application load.

Hard to test in an ASP.NET app but in a winform/console app it's easy
to verify because you can change the app.config file before calling
ConfigurationSettings.AppSettings and your changes are reflect (not
usually a good idea but we did this in one situation where we wanted a
console app to share a config file with another app sothe console app
copied the file on startup).

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 11 Jan 2007 15:16:47 -0500, "Ignacio Machin \( .NET/ C# MVP
\)" <machin TA laceupsolutions.comwrote:
>| string blah = ConfigurationSettings.AppSettings["foo"]
|
Not much, only a lookup in some struct in memory ( hashtable, etc). At some
moment the file needs to be loaded. IMO (but I have no fact to prove it) it
happens when the application loads.

Also remember that even as the file remains closed the engine keeps an eye
on it (probably using a FileSystemWatcher) to detect change, if it does it
reload the entire app
Jan 11 '07 #3
if ur accessing web.config, use WebConfigurationManager - its faster than the
basic ConfigurationManager.
Jan 12 '07 #4

WebConfigurationManager is new to .NET 2.0 and the original post asked
about ConfigurationSettings.AppSettings which is obsolete in .NET 2.0,
implying he's using .NET 1.1.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 11 Jan 2007 17:31:00 -0800, XOR
<XO*@discussions.microsoft.comwrote:
>if ur accessing web.config, use WebConfigurationManager - its faster than the
basic ConfigurationManager.
Jan 12 '07 #5
Hi,

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:hb********************************@4ax.com...
|
| It loads the first time ConfigurationSettings.AppSettings is called,
| not necessarily on application load.
|
| Hard to test in an ASP.NET app but in a winform/console app it's easy
| to verify because you can change the app.config file before calling
| ConfigurationSettings.AppSettings and your changes are reflect (not
| usually a good idea but we did this in one situation where we wanted a
| console app to share a config file with another app sothe console app
| copied the file on startup).

I think that the treatmean is different between web and win apps, in win app
as you mentioned before you can change the config while the app is running
and before the app access it without any consequence. If you do so in a web
app the application will restart.
--
Ignacio Machin
machin AT laceupsolutions com
Jan 12 '07 #6

The treament related to changing the file is different, but the O.P.'s
question was about when the data is loaded and how it's cached which
is the same--on first access.

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 12 Jan 2007 09:58:43 -0500, "Ignacio Machin \( .NET/ C# MVP
\)" <machin TA laceupsolutions.comwrote:
>Hi,

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:hb********************************@4ax.com.. .
|
| It loads the first time ConfigurationSettings.AppSettings is called,
| not necessarily on application load.
|
| Hard to test in an ASP.NET app but in a winform/console app it's easy
| to verify because you can change the app.config file before calling
| ConfigurationSettings.AppSettings and your changes are reflect (not
| usually a good idea but we did this in one situation where we wanted a
| console app to share a config file with another app sothe console app
| copied the file on startup).

I think that the treatmean is different between web and win apps, in win app
as you mentioned before you can change the config while the app is running
and before the app access it without any consequence. If you do so in a web
app the application will restart.
Jan 16 '07 #7
Hi,

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:dk********************************@4ax.com...
|
| The treament related to changing the file is different, but the O.P.'s
| question was about when the data is loaded and how it's cached which
| is the same--on first access.

Do you have a link where this is described?

Honestly I would find dificult to understand why it's loaded at first use,
and being "watched" from the beginning. Unless of course that the first
thing that happen when an app is loaded depends of the config, then it will
load (at the start of the app). In this escenario the file is loaded at
first use which coincide with the load of the app. IMHO I think this is the
way it happens

--
Ignacio Machin
machin AT laceupsolutions com
Jan 16 '07 #8

Use Reflector and look at ConfigurationSettings.GetConfig. It's
initialized on first use.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Tue, 16 Jan 2007 13:50:07 -0500, "Ignacio Machin \( .NET/ C# MVP
\)" <machin TA laceupsolutions.comwrote:
>Hi,

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:dk********************************@4ax.com.. .
|
| The treament related to changing the file is different, but the O.P.'s
| question was about when the data is loaded and how it's cached which
| is the same--on first access.

Do you have a link where this is described?

Honestly I would find dificult to understand why it's loaded at first use,
and being "watched" from the beginning. Unless of course that the first
thing that happen when an app is loaded depends of the config, then it will
load (at the start of the app). In this escenario the file is loaded at
first use which coincide with the load of the app. IMHO I think this is the
way it happens
Jan 16 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
I am a user of the ConfigurationSettings.AppSettings("KeyName") in asp.net 1.1 so after reading about the new ConnectionStrings collection in "Intoducing Microsoft ASP.NET 2.0 by Dino Esposito on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.