appdomain多次加载一个com dll并保持内存隔离
有一个COM DLL(VC6.0 ATL向导内置),我想利用appdomain的身份来实现一个进程创建多个appdomain,每个进程都加载这个COM DLL,并确保每个COM DLL都有独立的内存空间。
例如
AppDomain Domain1 = AppDomain.CreateDomain(“D1”); AppDomain Domain2 = AppDomain.CreateDomain("D2");
对象 obj1 = Domain1.CreateInstanceFromAndUnwrap("UnManagedCOMDLL.dll", "UnManagedCOMDLL.ShowTag");
object obj2 = Domain2.CreateInstanceFromAndUnwrap("UnManagedCOMDLL.dll", "UnManagedCOMDLL.ShowTag")
在这个dll中,有一个全局变量,每次加载时,都会++。虽然com加载在不同的appdomain中,但是全局变量是互相共享的。
为什么会出现这样的结果呢? appdomain 应该保持内存隔离,但失败了。
但是,对于托管 dll,appdomain 可以工作。
帮我!!!!!
There is a COM DLL(VC6.0 ATL wizard built), I want to use appdomain's identities to impliment one process creates multiple appdomain,every one load this COM DLL and ensure everyone COM DLL to have isolated memory space。
For example
AppDomain Domain1 = AppDomain.CreateDomain("D1");
AppDomain Domain2 = AppDomain.CreateDomain("D2");
object obj1 = Domain1.CreateInstanceFromAndUnwrap("UnManagedCOMDLL.dll", "UnManagedCOMDLL.ShowTag");
object obj2 = Domain2.CreateInstanceFromAndUnwrap("UnManagedCOMDLL.dll", "UnManagedCOMDLL.ShowTag")
In this dll,there is a global variable, every time it loads,it++. although the com loaded in different appdomain,the global variable is shared by each other.
why is such result happened? appdomain should keep memory iasolation, but it failed.
however, to managed dll, appdomain can work.
help me!!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您将 COM 对象加载到一个或多个托管进程中。这是您可以为他们提供您想要的隔离类型的唯一方法。您可以自己动手,或者研究一下 COM+
I suggest you load the COM object into one or more hosting processes. That is the only way you can give them the type of isolation you are looking for. You can roll your own, or perhaps look into COM+