473,396 Members | 2,024 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,396 software developers and data experts.

appSetting in .Config file

Hi,
In a windows service, I have some appSettings. If I during runtime changes
one of the values, is it availabele to the service from that moment? Or do I
have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart
Mar 3 '06 #1
6 2540
it depends on when you read your values?

Normally if you read in the values at startup your service will not see
the changes in the config file.

but you can program a sort of loop in your application where it checks
if changes are made to the config file, but that is not a very clean
way to handle such things in my honest opinion.

Why do need this for? Maybe i can help.

Mar 3 '06 #2
Mats,
If you use the standard app.config arrangement where the config file gets
named myService.exe.config, the configuration file is automatically read one
time at startup. For dynamic updating, you need to add a separate
filesystemwatcher and probably keep your dynamic settings in a separate
config file. A change in that would trigger re-reading the file without
having to stop the service. Actually, I use database entries and SQL Cache
Dependency as an alternative to that.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mats-Lennart Hansson" wrote:
Hi,
In a windows service, I have some appSettings. If I during runtime changes
one of the values, is it availabele to the service from that moment? Or do I
have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart

Mar 3 '06 #3
> but you can program a sort of loop in your application where it checks
if changes are made to the config file, but that is not a very clean
way to handle such things in my honest opinion.
No loop is necessary. The config files are cached when the app is started,
and when they are changed. There is no IO cost to reading directly from the
Application Configuration at any time during the lifetime of the app.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
"DarkSider" <vo********@gmail.com> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com... it depends on when you read your values?

Normally if you read in the values at startup your service will not see
the changes in the config file.

but you can program a sort of loop in your application where it checks
if changes are made to the config file, but that is not a very clean
way to handle such things in my honest opinion.

Why do need this for? Maybe i can help.

Mar 3 '06 #4
Which version of the Framework are you using?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
"Mats-Lennart Hansson" <ap********@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP14.phx.gbl...
Hi,
In a windows service, I have some appSettings. If I during runtime changes
one of the values, is it availabele to the service from that moment? Or do
I have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart

Mar 3 '06 #5
Here is a post from Junfeng Zhang that may help to clear all this up:

http://blogs.msdn.com/junfeng/archiv...20/376880.aspx
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mats-Lennart Hansson" wrote:
Hi,
In a windows service, I have some appSettings. If I during runtime changes
one of the values, is it availabele to the service from that moment? Or do I
have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart

Mar 3 '06 #6
Thanks, that's exactly what I was looking for. Unfortunately, the
functionality wasn't what I hoped for. But hey, that's life :)

Thanks to all that responded.

/Mats-Lennart

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:CB**********************************@microsof t.com...
Here is a post from Junfeng Zhang that may help to clear all this up:

http://blogs.msdn.com/junfeng/archiv...20/376880.aspx
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mats-Lennart Hansson" wrote:
Hi,
In a windows service, I have some appSettings. If I during runtime
changes
one of the values, is it availabele to the service from that moment? Or
do I
have to restart the service before I can access the new value?

Ex.
I have this entry in my .config file:
<add key="Path" value="C:\test" />

and change it to:
<add key="Path" value="C:\someOtherFolder" />

Do I need to restart the service to be able to read the new value?

Thanks
/Mats-Lennart

Mar 3 '06 #7

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

Similar topics

2
by: Ellis Yu | last post by:
Dear All, I use function configurationsettings.appsetting to retrieve the connection string value which stored in a file app.config. At the beginning, it's fine that it can pick up the value...
2
by: keith | last post by:
In my app, an executable (app.exe) calls functions from an assembly dll (subapp.dll). app.exe has config file: app.exe.config <?xml version="1.0" encoding="utf-8" ?> <configuration>...
1
by: Maziar Aflatoun | last post by:
Hi everyone, I'm tring to read the appSettings from my Web.config file in Visual Studio.Net (Code behind page) and it doesn't recognize ConfigurationSettings.AppSetting? Yet it works in my .aspx...
2
by: John Spiegel | last post by:
Hi all, I'm looking for suggestions on storing classifications of application settings in a WinForms app. I've got a couple ideas using XML config files. One is to have a set of .config files...
1
by: softwareakash | last post by:
Hi I have a class library which takes some values from web config / app config files when called. I am initialising these values when my object gets called. Is there any method to find out if...
16
by: Robert Dufour | last post by:
Here's the class code snippet Imports System.Configuration.ConfigurationManager Public Class Class1 Public _strTestSetting As String Public Sub SetTestsetting()
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.