Export (0) Print
Expand All

AnonymousPipeClientStream.ReadMode Property

Sets the reading mode for the AnonymousPipeClientStream object.

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

public override PipeTransmissionMode ReadMode { set; }


The transmission mode is not valid. For anonymous pipes, only Byte is supported.


The transmission mode is Message.


The connection is broken or another I/O error occurs.


The pipe is closed.

Anonymous pipes do not support Message read mode.

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. The NotSupportedException is caught when the ReadMode property is set to Message.

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...");

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft