.NET 中的管道操作Pipe Operations in .NET

管道为进程间通信提供了平台。Pipes provide a means for interprocess communication. 管道分为两种类型:There are two types of pipes:

  • 匿名管道。Anonymous pipes.

    匿名管道在本地计算机上提供进程间通信。Anonymous pipes provide interprocess communication on a local computer. 与命名管道相比,虽然匿名管道需要的开销更少,但提供的服务有限。Anonymous pipes require less overhead than named pipes but offer limited services. 匿名管道是单向的,不能通过网络使用。Anonymous pipes are one-way and cannot be used over a network. 仅支持一个服务器实例。They support only a single server instance. 匿名管道可用于线程间通信,也可用于父进程和子进程之间的通信,因为管道句柄可以轻松传递给所创建的子进程。Anonymous pipes are useful for communication between threads, or between parent and child processes where the pipe handles can be easily passed to the child process when it is created.

    在 .NET 中,可通过使用 AnonymousPipeServerStreamAnonymousPipeClientStream 类来实现匿名管道。In .NET, you implement anonymous pipes by using the AnonymousPipeServerStream and AnonymousPipeClientStream classes.

    请参阅如何:使用匿名管道进行本地进程间通信See How to: Use Anonymous Pipes for Local Interprocess Communication.

  • 命名管道。Named pipes.

    命名管道在管道服务器和一个或多个管道客户端之间提供进程间通信。Named pipes provide interprocess communication between a pipe server and one or more pipe clients. 命名管道可以是单向的,也可以是双向的。Named pipes can be one-way or duplex. 它们支持基于消息的通信,并允许多个客户端使用相同的管道名称同时连接到服务器进程。They support message-based communication and allow multiple clients to connect simultaneously to the server process using the same pipe name. 命名管道还支持模拟,这样连接进程就可以在远程服务器上使用自己的权限。Named pipes also support impersonation, which enables connecting processes to use their own permissions on remote servers.

    在 .NET 中,可通过使用 NamedPipeServerStreamNamedPipeClientStream 类来实现命名管道。In .NET, you implement named pipes by using the NamedPipeServerStream and NamedPipeClientStream classes.

    请参阅如何:使用命名管道进行网络进程间通信See How to: Use Named Pipes for Network Interprocess Communication.

请参阅See also