C# 中的 IPC 机制 - 使用和最佳实践

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 10:10:56  来源:igfitidea点击:

IPC Mechanisms in C# - Usage and Best Practices

提问by prakash

I have used IPC in win32 code a while ago. [Critical sections, events & semaphores]

不久前我在 win32 代码中使用了 IPC。[关键部分、事件和信号量]

How is the scene in .NET enviroment? Are there any tutorial explaining all available options and when to use and why?

.NET 环境中的场景如何?是否有任何教程解释所有可用选项以及何时使用以及为什么?

采纳答案by aku

Most recent Microsoft's stuff in IPC is Windows Communication Foundation. Actually there is nothing new in the lower level (tcp, upd, named pipes etc) But WCF simplifies IPC development greatly.

微软最近在 IPC 中的东西是Windows Communication Foundation。实际上,在较低级别(tcp、upd、命名管道等)中并没有什么新东西,但是 WCF 极大地简化了 IPC 开发。

Useful resource:

有用的资源:

and of course MSDN on WCF

当然还有WCF 上的 MSDN

回答by ibz

There is also .NET Remoting, which I found quite cool, but I guess they are obsoleting it now that they have WCF.

还有 .NET Remoting,我觉得它很酷,但我猜他们现在已经过时了,因为他们有 WCF。

回答by Cody Brocious

I tend to use named pipes or Unix sockets (depending on whether I'm targetting MS.NET or Mono -- I have a class that abstracts it away) since it's easy to use, portable, and allows me to easily interoperate with unmanaged code. That said, if you're only dealing with managed code, go with WCF or remoting -- the latter if you need Mono support, since their WCF support simply isn't there yet.

我倾向于使用命名管道或 Unix 套接字(取决于我的目标是 MS.NET 还是 Mono——我有一个将它抽象出来的类),因为它易于使用、可移植,并且允许我轻松地与非托管代码进行互操作. 也就是说,如果您只处理托管代码,请使用 WCF 或远程处理——如果您需要 Mono 支持,则使用后者,因为它们的 WCF 支持尚不存在。

回答by Kent Boogaart

It sounds as though you're interested in synchronization techniques rather than communication. If so, you might like to start here, or perhaps this more concise overview.

听起来好像您对同步技术而不是通信感兴趣。如果是这样,您可能希望从这里开始,或者更简洁的概述

回答by Deleted

Apart from the obvious (WCF), there is a ZeroMQ binding for C#/CLR which is pretty good:

除了明显的(WCF)之外,还有一个用于 C#/CLR 的 ZeroMQ 绑定,它非常好:

http://www.zeromq.org/bindings:clr

http://www.zeromq.org/bindings:clr

Does message-oriented IPC, pub/sub and various other strategies with much less code and config than WCF.

使用比 WCF 少得多的代码和配置来执行面向消息的 IPC、发布/订阅和各种其他策略。

It's also at least an order of magnitude faster than anything else and has less latency if you require low latency comms.

如果您需要低延迟通信,它也至少比其他任何东西快一个数量级,并且延迟更少。

With respects to semaphores, locks, mutexes etc. If you share by communicating rather than communicate by sharing, you'll have a whole load less hassle than the traditional paradigm.

关于信号量、锁、互斥体等。如果您通过通信进行共享而不是通过共享进行通信,那么与传统范式相比,您将拥有更少的麻烦。

回答by Demir

I would recommend using Memory Mapped Files if you need to use on the machine domain not communication through network. See the following link.

如果您需要在机器域上使用而不是通过网络进行通信,我会建议使用内存映射文件。请参阅以下链接。

http://techmikael.blogspot.com/2010/02/blazing-fast-ipc-in-net-4-wcf-vs.html

http://techmikael.blogspot.com/2010/02/blazing-fast-ipc-in-net-4-wcf-vs.html