开发者

Configure Shadow Copy using app.config

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, f开发者_如何学JAVArom Asp.Net

<hostingEnvironment 
    idleTimeout="Infinite" 
    shutdownTimeout="30" 
    shadowCopyBinAssemblies="true" />

Any suggestions?


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.

  1. Create a child AppDomain to host your service code, and configure shadow copying.
  2. Use something like a FileSystemWatcher to monitor the original bin directory.
  3. When files change, tear down your 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜