使用 app.config 配置卷影复制
让我先解释一下场景。
我从一个安装库安装了多个服务副本(例如 10 个)。现在我想更新其中一个dll。我需要停止所有服务,更新 dll 并再次重新启动服务。
为了避免这种情况,我在代码中使用了 ShadowCopying。这样就可以在不停止所有服务的情况下更新dll。如下。
static void Main(string[] args)
{
AppDomain.CurrentDomain.SetCachePath(@"C:\Cache");
AppDomain.CurrentDomain.SetShadowCopyPath(AppDomain.CurrentDomain.BaseDirectory);
AppDomain.CurrentDomain.SetShadowCopyFiles();
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SampleService(serviceName)
};
ServiceBase.Run(ServicesToRun);
}
现在我试图通过 app.config 文件实现相同的目标,如下所示,来自 Asp.Net
<hostingEnvironment
idleTimeout="Infinite"
shutdownTimeout="30"
shadowCopyBinAssemblies="true" />
有什么建议吗?
Let me explain the scenario first.
I have installed multiple copies (Say 10) of Services from a single install base. Now I want to update one of the dll. I need to Stop all the services, update the dll and restart the Service again.
To avoid the situation, I used ShadowCopying in code. So that the dlls can be updated without stopping all the services. It is as follows.
static void Main(string[] args)
{
AppDomain.CurrentDomain.SetCachePath(@"C:\Cache");
AppDomain.CurrentDomain.SetShadowCopyPath(AppDomain.CurrentDomain.BaseDirectory);
AppDomain.CurrentDomain.SetShadowCopyFiles();
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SampleService(serviceName)
};
ServiceBase.Run(ServicesToRun);
}
Now I am trying to achieve the same via app.config file, as follows, from Asp.Net
<hostingEnvironment
idleTimeout="Infinite"
shutdownTimeout="30"
shadowCopyBinAssemblies="true" />
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ASP.Net 托管环境具有对管理应用程序回收的内置支持。
Windows .Net 服务使用不支持此功能的标准 CLR 主机。您必须实现自己的,例如
AppDomain
来托管您的服务代码,并配置卷影复制。AppDomain
并创建一个新的并重新加载。ASP.Net 主机按照这些思路执行一些操作(但也能够管理现有请求、在执行此操作时对新请求进行排队等)。
The ASP.Net hosting environment has built-in support for managing application recycling.
Windows .Net services use the standard CLR host which does not have this support. You would have to implement your own e.g.
AppDomain
to host your service code, and configure shadow copying.FileSystemWatcher
to monitor the original bin directory.AppDomain
and create a new one and reload.The ASP.Net host does something along these lines (but also has the ability to manage existing requests, queue new requests whilst this is going on, etc).