移动跨应用程序域对象的.NET [英] Moving objects across AppDomains in .NET

查看:139
本文介绍了移动跨应用程序域对象的.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法能够有效地共享或移动.NET对象跨应用程序域?我知道的AppDomain的目的是提供隔离 - 不过,我有一个情况下,我需要将一个比较大的缓存组是昂贵的计算和创建不可改变的对象。目前,我有一个序列化的方法这样的作品,相反却是缓慢的。

Is there a way to efficiently share or move .NET objects across AppDomains? I realize that the intent of AppDomains is to provide isolation - however I have a case where I need to move a relatively large, cached set of immutable objects that are expensive to compute and create. At the moment, I have a serialization approach that works, but is rather slow.

推荐答案

您不能移动跨一个AppDomain对象没有序列化它。这是一个AppDomain的主要观点 - 你几乎可以把它看成是一个完全独立的过程。

You cannot move an object across an AppDomain without serializing it. That is the main point of an AppDomain - you can almost think of it as a completely separate process.

这是在哪里MarshallByRefObject用武之地。它可以让你的使用从通过Remoting其他的AppDomain对象,而不必将其跨AppDomain的边界序列。您是通过远程还在工作,所以它会比保持对象在同一个AppDomain中慢,但如果对象是大的,你不经常使用它,与它的序列化和反序列化相比,这样可以节省大量的时间它使一个新的副本在第二AppDomain中。

This is where MarshallByRefObject comes into play. It allows you to use the object from the other AppDomain via Remoting, without having to serialize it across the AppDomain boundary. You're still working via remoting, so it will be slower than keeping the object in the same AppDomain, but if the object is large and you are using it infrequently, this can save a huge amount of time when compared with serializing it and unserializing it to make a new copy in the second AppDomain.

这篇关于移动跨应用程序域对象的.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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