窗口服务 - 配置文件 [英] windows service - config file
问题描述
我知道这可能已经问过,但我似乎无法找到正确的答案对我来说。
I know this has probably been asked before but I can't seem to find the right answer for me.
我有一个名为Windows服务的的 foobar.exe 的。我有一个名为应用程序配置文件的的 foobar.exe.config 的在同一文件夹。
I have a windows service named foobar.exe. I have an application configuration file named foobar.exe.config in the same folder.
是配置文件只在启动时读取?
我想更改配置文件,而无需重新启动该服务,但是这是我能得到新的设置读取的唯一方法。
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.
我究竟做错了什么?
可以在Windows的服务有一个动态的配置文件?
推荐答案
.NET应用程序将读取其配置文件在启动并缓存性能的原因。
.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
Windows NT服务可以以一种特殊的<一个回应href="http://msdn.microsoft.com/en-US/library/system.serviceprocess.servicebase.oncustomcommand%28v=VS.80%29.aspx"><$c$c>OnCustomCommand$c$c>事件。你可以实现这样的事件处理程序重新加载配置,当你做更改配置,你可以有一个小工具的信号为您服务的配置已发生变化,发送自定义命令为您服务
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
这篇关于窗口服务 - 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!