Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

AnonymousPipeClientStream Constructor (PipeDirection, SafePipeHandle)

Initializes a new instance of the AnonymousPipeClientStream class from the specified handle.

Namespace:  System.IO.Pipes
Assembly:  System.Core (in System.Core.dll)
public AnonymousPipeClientStream(
	PipeDirection direction,
	SafePipeHandle safePipeHandle
)

Parameters

direction
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.

safePipeHandle
Type: Microsoft.Win32.SafeHandles.SafePipeHandle

A safe handle for the pipe that this AnonymousPipeClientStream object will encapsulate.

ExceptionCondition
ArgumentException

safePipeHandle is not a valid handle.

ArgumentNullException

safePipeHandle is null.

NotSupportedException

direction is set to InOut.

IOException

An I/O error, such as a disk error, has occurred.

-or-

The stream has been closed.

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(args[0]))
            {

                Console.WriteLine("Current TransmissionMode: {0}.",
                   pipeClient.TransmissionMode);

                // Anonymous Pipes do not support Message mode. 
                try
                {
                    Console.WriteLine("Setting ReadMode to \"Message\".");
                    pipeClient.ReadMode = PipeTransmissionMode.Message;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine("EXCEPTION: {0}", e.Message);
                }

                using (StreamReader sr = new StreamReader(pipeClient))
                {
                    // Display the read text to the console 
                    string temp;
                    while ((temp = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(temp);
                    }
                }
            }
        }
        Console.Write("Press Enter to continue...");
        Console.ReadLine();
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
  • Demand 

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

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.