用C#在2个进程之间进行通信的最快,最简单的方法是什么? [英] What is the fastest and easiest way to communicate between 2 processes in C#?

查看:1092
本文介绍了用C#在2个进程之间进行通信的最快,最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主要c#应用程序中,我使用Process.Start方法启动了许多从属进程. (在同一台PC上)

From my main c# app, I start many slave process with Process.Start method. (on the same PC)

就在开始这些从属进程之前,我在 XML文件中序列化了一些数据(我已经序列化了类),这些数据在Process类的参数中传递.

Just before starting those slave process, I serialize some data (I have serialized class) in XML files which are passed in the arguments of Process class.

在每个从属进程中,对这些数据进行反序列化并进行计算.为了将结果发送到主进程,对XML进行了新的序列化.

In each slave process, those data are deserialized and a computation is done. A new serialization is done to XML in order to send result to the main process.

我的应用程序可以运行,但是性能很差. 序列化/反序列化操作的时间太长,因为每个XML文件的大小约为1.5 Mo ...

My apps works but the performance are very bad. The time of serialization/deserialization operation is too long because the size of each XML file is about 1,5 Mo...

在主应用程序和从属进程之间的这种简单通信中,我确实需要高性能.

如何轻松修改代码以提高性能? Nb:将来我的主进程将使用64位,而从属进程将使用32位.

How can I easily modify my code to improve this performance ? Nb : in the future my main process will be in 64 bits and the slaves process in 32 bits.

我听说有些应用程序允许虚拟化RAM中的硬盘?是否存在?免费吗?

I have heard that some apps allows to virtualize hard disk in RAM ? Does it exist ? Is it free ?

我听说过WCF,命名管道,内存映射等,但是我似乎很想使用....?

I have heard of WCF, Named Pipe, Memory Mapped, etc but I seems to be heavy to use ....?

推荐答案

内存映射文件(MMF)是最快的方法.正如您所指出的,问题出在序列化而不是传输本身.序列化对于任何传输,甚至MMF都是必需的(最简单的情况除外,当简单的数据记录可以按顺序排列在内存中时). XML速度不快-任何形式的二进制序列化都可以更好地工作.

Memory-mapped files (MMF) are the fastest method. The problem though, as you point, is in serialization rather than transfer itself. Serialization is necessary for any transport, even MMFs (except the simplest cases when you have simple data records which can be laid out sequentially in memory). XML is not fast - binary serialization of any kind would work much better.

这篇关于用C#在2个进程之间进行通信的最快,最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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