By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
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

Jul 21 '05 #2

P: n/a
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

Jul 21 '05 #3

P: n/a
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

Jul 21 '05 #4

P: n/a
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

Jul 21 '05 #5

P: n/a
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
Jul 21 '05 #6

P: n/a
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

Jul 21 '05 #7

P: n/a
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

Jul 21 '05 #8

P: n/a
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

Jul 21 '05 #9

P: n/a
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


Jul 21 '05 #10

P: n/a
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

Jul 21 '05 #11

P: n/a
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

Jul 21 '05 #12

P: n/a
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


Jul 21 '05 #13

P: n/a
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

Jul 21 '05 #14

P: n/a
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


Jul 21 '05 #15

P: n/a
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)
Jul 21 '05 #16

P: n/a
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


Jul 21 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.