Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

.net - windows service - config file

I know this has probably been asked before but I can't seem to find the right answer for me.

I have a windows service named foobar.exe. I have an application configuration file named foobar.exe.config in the same folder.

Is the config file only read at startup?

I would like to make changes to the config file without having to restart the service but that is the only way I can get the new settings read.

What am I doing wrong?

Can a windows service have a dynamic config file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.NET applications will read their config files at startup and cache them for performance reasons.

I see two basic ways around this:

  • in your service, keep track of the last update date/time for the config file. Check this last update date regularly and if you detect a change, re-load the config file

  • a Windows NT service can respond to a special OnCustomCommand event. You could implement such an event handler to reload the config, and when you do change the config, you could have a small utility to signal to your service that the config has changed and send that "custom command" to your service


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...