AnonymousPipeClientStream Constructor (PipeDirection, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the AnonymousPipeClientStream class with the specified pipe direction and a string representation of the pipe handle.

Namespace:   System.IO.Pipes
Assembly:  System.Core (in System.Core.dll)

public AnonymousPipeClientStream(
	PipeDirection direction,
	string pipeHandleAsString


Type: System.IO.Pipes.PipeDirection

One of the enumeration values that determines the direction of the pipe.

Anonymous pipes can only be in one direction, so direction cannot be set to InOut.

Type: System.String

A string that represents the pipe handle.

Exception Condition

pipeHandleAsString is an invalid handle.


pipeHandleAsString is null.


direction is set to InOut.

A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.

The following example demonstrates a way to send a string from a parent process to a child process by using anonymous pipes. In this example, an AnonymousPipeClientStream object is created in a child process with a PipeDirection value of In.

using System;
using System.IO;
using System.IO.Pipes;

class PipeClient
    static void Main(string[] args)
        if (args.Length > 0)
            using (PipeStream pipeClient =
                new AnonymousPipeClientStream(PipeDirection.In, args[0]))
                // Show that anonymous Pipes do not support Message mode.
                    Console.WriteLine("[CLIENT] Setting ReadMode to \"Message\".");
                    pipeClient.ReadMode = PipeTransmissionMode.Message;
                catch (NotSupportedException e)
                    Console.WriteLine("[CLIENT] Execption:\n    {0}", e.Message);

                Console.WriteLine("[CLIENT] Current TransmissionMode: {0}.",

                using (StreamReader sr = new StreamReader(pipeClient))
                    // Display the read text to the console
                    string temp;

                    // Wait for 'sync message' from the server.
                        Console.WriteLine("[CLIENT] Wait for sync...");
                        temp = sr.ReadLine();
                    while (!temp.StartsWith("SYNC"));

                    // Read the server data and echo to the console.
                    while ((temp = sr.ReadLine()) != null)
                        Console.WriteLine("[CLIENT] Echo: " + temp);
        Console.Write("[CLIENT] Press Enter to continue...");


for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Available since 3.5
Return to top