在运行时更新应用程序的库(DLL)? [英] Update application's libraries (DLLs) during runtime?

查看:118
本文介绍了在运行时更新应用程序的库(DLL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中运行应用程序时是否有更新DLL的方法?例如,如果有一个函数看起来像这样的DLL:

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

它在一个线程中被调用,在呼叫之间休眠1秒。 p>

现在,我写了新版本:

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

我可以在运行时使用这个新的DLL更新旧的DLL吗?重要的是,我的APP始终运行,没有米什么...但我猜,更新库是一个例外。我是错的吗?

解决方案

如果你的代码可以在逻辑上被隔离成独立的DLL,你可以使用(如其他人所提到的)远程处理或System.AddIn框架。根据功能的集成程度如何,可能会太复杂和/或过度。 System.AddIn方法的一个好处是可以卸载程序集,将dll替换为新版本,并在不停止应用程序的情况下重新加载,但它仅适用于轻量级插件架构,并且跨隔离边界的性能是如果区域足够小(如 http://www.ironpython.net/ ) - 您可以将代码存储在文本文件(或数据库,或任何地方)中,并从中加载/运行。然后只需更换代码并重新加载。



我想这一切都归结于您是否可以识别出可能发生的变化,如果有隔离过程会适合它要做到这一点,整个应用程序是不容易的!


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!

这篇关于在运行时更新应用程序的库(DLL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆