我可以安全地重命名/移动进程已加载的 dll 吗?
我有一个由进程加载和文件锁定的 dll,我想用较新的版本更新它。我正在寻找一种替代方法来终止进程以在更新 dll 之前释放文件锁。现有的实时进程仍然使用旧版本是可以的,只要新实例化的进程采用新的逻辑即可。
看来我可以简单地重命名/移动 dll,并且实时进程似乎仍然运行良好。这样做安全吗?如果dll的代码已经加载到进程中那么为什么还需要锁定dll呢?
I have a dll that is loaded and file-locked by a process, and I would like to update it with a newer version. I'm looking for an alternative to terminating the process to release the file lock before updating the dll. It is okay that the existing live processes still uses the old version, as long as newly instantiated ones pick up the new logic.
It seems that I can simply rename/move the dll and the live process still seems to work well. Is it safe to do this? If the dll's code has already been loaded into the process then why does it still need to lock the dll?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
移动任何随机应用程序使用的所有 dll 并不总是可以的。某些应用程序(例如 asp.net)使用卷影复制概念,它们实际上复制 dll 并使用该副本,从而使您可以自由修改原始文件。对于 ASP.NET,如果您修改原始的 ASP.NET,将自动使用新的 DLL 生成一个新的应用程序域,并正常关闭旧的应用程序域。
如果您引用的应用程序锁定了 dll,那么您就无法安全地更改它。
It is not always ok to move all dll's used by any random application. Some applications, like asp.net, use a shadow copy concept where they actually copy the dll and use the copy leaving you free to modify the original. In the case of asp.net, if you modify the original asp.net will automatically spool up a new app domain using the new dll and gracefully shut down the old one.
If the application you're referring to has a lock on the dll, then you can't safely change it.
这取决于您的 dll/应用程序。例如,dll可以使用共享内存,或者实现进程间通信。新的 dll 版本可能会以不同的方式实现它。因此,一旦新实例启动,内存中就会有两个冲突的版本。
因此,在一般情况下它并不安全,尽管在您的特定情况下可能没问题。
It depends on your dll/application. For example, dll may use shared memory, or implement inter-process communication. New dll version may implement it differently. So once new instance will start, you'll have two conflicting versions in memory.
So it's not safe in general case, though in your particular case it may be OK.