Permalink
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (40 sloc) 3.55 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Use Anonymous Pipes for Local Interprocess Communication
03/30/2017
.net
dotnet-standard
article
anonymous pipes [.NET Framework]
parent-child communication [.NET Framework]
pipes [.NET Framework]
one-way communication [.NET Framework]
local computer communication [.NET Framework], pipes
e7773c77-c646-4a01-8a96-a003d59fc4c9
9
mairaw
mairaw
wpickett

How to: Use Anonymous Pipes for Local Interprocess Communication

Anonymous pipes provide interprocess communication on a local computer. They offer less functionality than named pipes, but also require less overhead. You can use anonymous pipes to make interprocess communication on a local computer easier. You cannot use anonymous pipes for communication over a network.

To implement anonymous pipes, use the xref:System.IO.Pipes.AnonymousPipeServerStream and xref:System.IO.Pipes.AnonymousPipeClientStream classes.

Example

The following example demonstrates a way to send a string from a parent process to a child process using anonymous pipes. This example creates an xref:System.IO.Pipes.AnonymousPipeServerStream object in a parent process with a xref:System.IO.Pipes.PipeDirection value of xref:System.IO.Pipes.PipeDirection.Out. The parent process then creates a child process by using a client handle to create an xref:System.IO.Pipes.AnonymousPipeClientStream object. The child process has a xref:System.IO.Pipes.PipeDirection value of xref:System.IO.Pipes.PipeDirection.In.

The parent process then sends a user-supplied string to the child process. The string is displayed to the console in the child process.

The following example shows the server process.

[!code-cppSystem.IO.Pipes.AnonymousPipeServerStream_Sample#01] [!code-csharpSystem.IO.Pipes.AnonymousPipeServerStream_Sample#01] [!code-vbSystem.IO.Pipes.AnonymousPipeServerStream_Sample#01]

Example

The following example shows the client process. The server process starts the client process and gives that process a client handle. The resulting executable from the client code should be named pipeClient.exe and be copied to the same directory as the server executable before running the server process.

[!code-cppSystem.IO.Pipes.AnonymousPipeClientStream_Sample#01] [!code-csharpSystem.IO.Pipes.AnonymousPipeClientStream_Sample#01] [!code-vbSystem.IO.Pipes.AnonymousPipeClientStream_Sample#01]

See Also

Pipes
How to: Use Named Pipes for Network Interprocess Communication