473,503 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

App.config doesn't 'refresh' once runned?

Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able to
change from time to time some parameters by changing them in the App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during start-up.

Is there a way to let the application use the new values in the App.config?
Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter
Nov 21 '05 #1
16 7586
I might be wrong but IIRC the app.config is part of the compile process, so I
think it's likely that you would have to recompile the project, unless you
specifically set it to look in that file during runtime (or know that it's
supposed to).
"DraguVaso" wrote:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able to
change from time to time some parameters by changing them in the App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during start-up.

Is there a way to let the application use the new values in the App.config?
Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #2
That's not true. App.Config is copied to exename.exe.config. It is then read
at runtime without needing any recompilation.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik


"Bonj" <Bo**@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
I might be wrong but IIRC the app.config is part of the compile process, so
I
think it's likely that you would have to recompile the project, unless you
specifically set it to look in that file during runtime (or know that it's
supposed to).
"DraguVaso" wrote:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I
do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #3
During (or after) compilation, the app.config file is just copied to the
target directory and renamed to <your_app_name>.exe.config. It's then read
on application startup.

I'm not aware of any way of reloading the configuration. The file contains
information that's required for application startup (like runtime
dependencies, etc.) which could not be reloaded.

If you need to change parameters during runtime, I suggest you either use
the registry or an some SQL database for your parameters OR use another
configuration file (say app.xml) and a FileSystemWathcher etc., but I guess
that would be way too complicated.

HTH,
Stefan

"Bonj" <Bo**@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
I might be wrong but IIRC the app.config is part of the compile process, so
I
think it's likely that you would have to recompile the project, unless you
specifically set it to look in that file during runtime (or know that it's
supposed to).
"DraguVaso" wrote:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I
do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #4
To answer your question specifically Dragu -

App.Config or exename.config changes are not read at runtime. (as far as I
know, and I think I'm right).

But it's easy to implement that. You need to implement your own app.config
basically, what I usually do is, I create a config directory. in that config
directory, I use a combination of FileSystemWatcher object and
System.EnterpriseServices caching to store config info that automatically
updates itself. The config info is nothing but an XML file, which is a class
that I serialized as XMLSerializer. So it's a very elegant solution.

An easier method is to put your relevant data in appSettings, and use the
FileSystemWatcher to re-read the appSettings whenever the file changes.

.... 4:30 AM .. EEEEEEEEEeeeeeeeeeeeee I need some sleep !!!

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #5
Sahil,

Nice idea,

I do not mean to go to bed what is as well a good idea of course, however
the use of the filesystemwatcher for this.

Cor
Nov 21 '05 #6
The app.config is read once at startup. In order for your service to detect
any changes, without making any code changes, you would need to restart the
service (assuming you are chaging the app.config file directly in the
services runtime directory).

IIS will detect changes to the web.config by starting up a new app domain,
loading the modified web.config, and then servicing all new requests through
the new app domain, until the old one can be unloaded. This is your third
option, in addition to what Sahils suggestion and restarting the service.

Hope this helps
Dan

"DraguVaso" wrote:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able to
change from time to time some parameters by changing them in the App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during start-up.

Is there a way to let the application use the new values in the App.config?
Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #7
Hehe .. thanks !! :)

I've half written the paged datatable. I just keep runnin' out of time man
... but I'll do it.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Sahil,

Nice idea,

I do not mean to go to bed what is as well a good idea of course, however
the use of the filesystemwatcher for this.

Cor

Nov 21 '05 #8
Pieter,
Just remember if you use ServiceController to stop & restart the service as
Dan suggests, that if you have multiple services in a single executable,
that you need to stop all the services for it to actually stop your EXE &
restart it.

In the service I am writing I plan on having the service manager (the
windows forms app) stop the service & restart my service (the windows
service app) via ServiceController.

If I had multiple services in a single EXE or just multiple services, I
would consider creating a second service that uses filesystemwatcher to
watch the app.config's of other services, then use ServiceController.Stop &
Restart to restart the respective services. Just be careful of the watcher
trying to restart itself ;-)

FWIW: I like the idea of separate App Domains, however what I am doing it
seems overkill right now...

Hope this helps
Jay
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #9
I have a solution which modifies app.config during runtime if that is
what you are getting at.

Post if you are interested.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:#H**************@TK2MSFTNGP15.phx.gbl:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I
do
this on an other way?

Thanks,

Pieter


Nov 21 '05 #10
Check out his article:

http://msdn.microsoft.com/library/de...et04222003.asp

About 3/4 of the way down, there's a section called Detecting Config File
Changes.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during start-up.
Is there a way to let the application use the new values in the App.config? Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #11
Hi scorpion,

I don't need it right now, but it will be really helpfull for future
projects, so it would be nice if you could post it here.

Thanks a lot in advance!

Pieter

"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a solution which modifies app.config during runtime if that is
what you are getting at.

Post if you are interested.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:#H**************@TK2MSFTNGP15.phx.gbl:
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able
to
change from time to time some parameters by changing them in the
App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during
start-up.

Is there a way to let the application use the new values in the
App.config?
Is there kind of some 'refresh' function that I should run? Or should I
do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #12
Great!
Exactly what I was looking for!

Thanks!

"Dave Hall" <dh***@nospam.deboy.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Check out his article:

http://msdn.microsoft.com/library/de...et04222003.asp
About 3/4 of the way down, there's a section called Detecting Config File
Changes.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able

to
change from time to time some parameters by changing them in the

App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during

start-up.

Is there a way to let the application use the new values in the

App.config?
Is there kind of some 'refresh' function that I should run? Or should I do this on an other way?

Thanks,

Pieter


Nov 21 '05 #13
have a look at
http://www.west-wind.com/presentatio...ationclass.asp

--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during start-up.
Is there a way to let the application use the new values in the App.config? Is there kind of some 'refresh' function that I should run? Or should I do
this on an other way?

Thanks,

Pieter

Nov 21 '05 #14
Excellent link Dave.
Thanks much

Steve

"Dave Hall" <dh***@nospam.deboy.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Check out his article:

http://msdn.microsoft.com/library/de...et04222003.asp
About 3/4 of the way down, there's a section called Detecting Config File
Changes.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a Windows Service running (made in VB.NET), and wanted to be able

to
change from time to time some parameters by changing them in the

App.config.
But it seems that the application doesn't use the changed values in the
App.config, but continue to use the values that were there during

start-up.

Is there a way to let the application use the new values in the

App.config?
Is there kind of some 'refresh' function that I should run? Or should I do this on an other way?

Thanks,

Pieter


Nov 21 '05 #15
The other posts seem a bit confusing. So here's a clearer reply

DraguVaso wrote:
I have a Windows Service running (made in VB.NET), and wanted to be
able to change from time to time some parameters by changing them in
the App.config. But it seems that the application doesn't use the
changed values in the App.config, but continue to use the values that
were there during start-up.
The application configuration file is named after the process, so if you
have a process called app.exe the configuration file is called
app.exe.config. VS.NET allows you to add a configuration file to a project
and it calls it app.config. When you build the project it copies this file
to the output folder and renames it according to the name of the process.
Is there a way to let the application use the new values in the
App.config? Is there kind of some 'refresh' function that I should
run? Or should I do this on an other way?


You cannot do it. The settings in the config file should be treated like
command line switches, once the process has started you cannot change them.

Actually, that is not strictly true, but it is a good rule of thumb. Here's
how it works. Each application domain in the process will read the
configuration and get its own copy, normally you will have just one
application domain in your process. When the appdomain wants to read a value
the *section* that contains the value is read (the sections are defined in
the machine.config file). The system will get the combination of the section
from machine.config and the application's file and use this XML to
initialize a configuration handler. The handler will generate some kind of
object from this (usually a collection object, but it doesn't have to be)
and the system stores it in a Hashtable in the appdomain. The next time that
a value is read from the section, the object cached in the Hashtable is
used.

This means that for an application domain, a setting is only read once from
the config file and after that the cached value is used. If you want to
change the config file during runtime you will have to use something like a
FileSystemWatcher on the config file, and when the file changes you will
have to use the XML classes to read the file and update your settings.

Richard
--
..NET training, development, consulting and mentoring
www.richardgrimes.com
my email ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
Nov 21 '05 #16
http://www.kjmsolutions.com/download...onfigstuff.ZIP

modifies app.config in real time.

But Richard is right. Use XML or something else. App.config was not
intended for this use.

"Richard Grimes [MVP]" <read my sig> wrote in message
news:#B**************@TK2MSFTNGP14.phx.gbl:
The other posts seem a bit confusing. So here's a clearer reply

DraguVaso wrote:
I have a Windows Service running (made in VB.NET), and wanted to be
able to change from time to time some parameters by changing them in
the App.config. But it seems that the application doesn't use the
changed values in the App.config, but continue to use the values that
were there during start-up.


The application configuration file is named after the process, so if you

have a process called app.exe the configuration file is called
app.exe.config. VS.NET allows you to add a configuration file to a project

and it calls it app.config. When you build the project it copies this file

to the output folder and renames it according to the name of the
process.
Is there a way to let the application use the new values in the
App.config? Is there kind of some 'refresh' function that I should
run? Or should I do this on an other way?


You cannot do it. The settings in the config file should be treated like

command line switches, once the process has started you cannot change
them.

Actually, that is not strictly true, but it is a good rule of thumb.
Here's
how it works. Each application domain in the process will read the
configuration and get its own copy, normally you will have just one
application domain in your process. When the appdomain wants to read a
value
the *section* that contains the value is read (the sections are defined in

the machine.config file). The system will get the combination of the
section
from machine.config and the application's file and use this XML to
initialize a configuration handler. The handler will generate some kind of

object from this (usually a collection object, but it doesn't have to be)

and the system stores it in a Hashtable in the appdomain. The next time
that
a value is read from the section, the object cached in the Hashtable is
used.

This means that for an application domain, a setting is only read once
from
the config file and after that the cached value is used. If you want to
change the config file during runtime you will have to use something like
a
FileSystemWatcher on the config file, and when the file changes you will

have to use the XML classes to read the file and update your settings.

Richard


Nov 21 '05 #17

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

Similar topics

16
4166
by: DraguVaso | last post by:
Hi, I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
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
7342
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...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.