且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

移动跨应用程序域对象的.NET

更新时间:2023-11-22 21:09:28

您不能移动跨一个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.