开发者

Update application's libraries (DLLs) during runtime?

开发者 https://www.devze.com 2023-01-17 13:59 出处:网络
Is there a way to update DLL while application is running in C#? For example, if there is DLL with a function that looks like this:

Is there a way to update DLL while application is running in C#? For example, if there is DLL with a function that looks like this:

void write()
{
    Console.WriteLine("LALALA");
}

And it is called in a thread with 1 second sleep between开发者_开发百科 calls.

Now, I wrote the new version:

void write()
{
    Console.WriteLine("LA LA LA\n");
}

Can I update old DLL with this new one during runtime? It is important that my APP is up and running all the time, no meter what... but I guess that updating libraries is an exception. Am I wrong?


If your code can be logically isolated into seperate DLLs, you can use (as others have mentioned) remoting or the System.AddIn framework. Depending on how integrated the functionality is though, it may be far too complicated and/or overkill. One benefit of the System.AddIn method is that assemblies can be unloaded, the dll replaced with a new version, and reloaded again without stopping the app - it is only designed for lightweight plugin architectures though, and performance across the 'isolation boundary' isn't going to be as great.

Scripting may also be useful if the areas are small enough (something like http://www.ironpython.net/) - you can store the code in text files (or database, or wherever) and load/run it from there. Then just replace the code and reload it.

I guess it all comes down to whether you can identify what is likely to change, and if there is an isolation process that would suit it. To do it to the entire application isn't easy!


You cannot update a dll while it is in use, however you can.

  • Make a copy of the dll with a new file name
  • Load the copy of the dll into an app domain
  • Talk to that app domain with .net remoting
  • When the original dll changes repeat the above

This is what Asp.net does under the covers. So another option is to use Aps.net to host your app.

0

精彩评论

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