问题描述
我有一个过程,可以有多个应用程序域。每个AppDomain中收集一些统计数据。在指定的时间后,我想积累这些统计数字,并将它们保存到一个文件中。
I have a process that can have multiple AppDomains. Each AppDomain collect some statistics. After a specified time, I want to accumulate these statistic and save them into a file.
做到这一点的方法之一是远程的,我希望避免的。
One way to do this is Remoting, which I want to avoid.
唯一的其他技术我心目中是保存在一个文件中的每个AppDomain中的数据,以及特定的时间后,在AppDomain中的一个收集所有数据和积累他们。
The only other technique I have in mind is to save each AppDomain's data in a file, and after a specific time, one of the AppDomain collects all data and accumulate them.
但是,这将是理想的,如果这所有可能的内存中进行,而不序列的信息,以应用程序域之间传递的成本。任何人有什么想法?
But it would be ideal if this all could be done in-memory, without the cost of serializing the information to pass between AppDomains. Anyone have any ideas?
推荐答案
要避免序列唯一的办法就是重新present使用的自MarshalByRefObject派生对象的数据,但在这种情况下,你仍然会有成本跨边界的AppDomain编组。这也可能涉及太多的code的重构/重写。
The only way to avoid serialisation is to represent your data using objects which derive from MarshalByRefObject, but in that case you will still have the cost of marshalling across the AppDomain boundaries. This may also involve the refactoring/re-writing of much of your code.
引用假设编组是不是一种选择,你将不得不在某个时候连载。它根本无法避免。这样做的一个方法是,尼尔·巴恩韦尔表明,与数据库,另一个将与本地文件你建议你自己。
Assuming marshalling by reference is not an option, you will have to serialise at some point. It simply cannot be avoided. One way to do this is as Neil Barnwell suggests, with a database, another would be with a local file as you suggest yourself.
这可能会或可能并不可行取决于你的交货时间表和/或.NET 4.0采用另一种方法,是使用内存映射文件,请参阅
Another way which may or may not feasible depending on your delivery timeline and/or .NET 4.0 adoption, would be to use a memory mapped file, see .Net Framework 4.0: Using memory mapped files.
这篇关于应用程序域之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!