AppDomain 和 MarshalByRefObject 生命周期:如何避免 RemotingException? [英] AppDomain and MarshalByRefObject life time : how to avoid RemotingException?
问题描述
当 MarshalByRef 对象从 AppDomain (1) 传递到另一个 (2) 时,如果在第二个 AppDomain (2) 中调用方法之前等待 6 分钟,您将收到 RemotingException :
When a MarshalByRef object is passed from an AppDomain (1) to another (2), if you wait 6 mins before calling a method on it in the second AppDomain (2) you will get a RemotingException :
System.Runtime.Remoting.RemotingException:对象 [...] 已断开连接或服务器上不存在.
System.Runtime.Remoting.RemotingException: Object [...] has been disconnected or does not exist at the server.
关于这个问题的一些文档:
Some documentation about this isse :
- http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/19/appdomains-and-remoting-life-time-service.aspx
- http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466.aspx - 实例生命周期,cbrumme 说我们应该解决这个问题.":(
- http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/19/appdomains-and-remoting-life-time-service.aspx
- http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466.aspx - Instance Lifetime, cbrumme says "We should fix this." :(
如果我错了,请纠正我:如果 InitializeLifetimeService 返回空值,则只能在 AppDomain 2 卸载时在 AppDomain 1 中收集对象,即使收集了代理?
Correct me if I'm wrong : if InitializeLifetimeService returns null, the object can only be collected in AppDomain 1 when AppDomain 2 is Unloaded, even if the proxy was collected ?
有没有办法禁用生命周期并使代理(在 AppDomain 2 中)和对象(在 AppDomain1 中)保持活动状态,直到代理完成?也许与ISponsor...?
Is there a way to disable life time and keep the proxy (in AppDomain 2) and the object (in AppDomain1) alive until the proxy is Finalized ? Maybe with ISponsor... ?
推荐答案
在此处查看答案:
基本上说:
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)]
public override object InitializeLifetimeService()
{
return null;
}
这篇关于AppDomain 和 MarshalByRefObject 生命周期:如何避免 RemotingException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!