Edit

Share via


AnonymousPipeClientStream Constructors

Definition

Initializes a new instance of the AnonymousPipeClientStream class.

Overloads

AnonymousPipeClientStream(String)

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

AnonymousPipeClientStream(PipeDirection, SafePipeHandle)

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

AnonymousPipeClientStream(PipeDirection, String)

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

AnonymousPipeClientStream(String)

Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs

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

public AnonymousPipeClientStream(string pipeHandleAsString);

Parameters

pipeHandleAsString
String

A string that represents the pipe handle.

Exceptions

pipeHandleAsString is not a valid pipe handle.

Examples

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.

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();
    }
}

Remarks

For constructors without a PipeDirection parameter, the default direction is In.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AnonymousPipeClientStream(PipeDirection, SafePipeHandle)

Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs

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

public AnonymousPipeClientStream(System.IO.Pipes.PipeDirection direction, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle);
[System.Security.SecurityCritical]
public AnonymousPipeClientStream(System.IO.Pipes.PipeDirection direction, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle);

Parameters

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

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

Attributes

Exceptions

safePipeHandle is not a valid handle.

safePipeHandle is null.

direction is set to InOut.

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

-or-

The stream has been closed.

Examples

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();
    }
}

Remarks

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AnonymousPipeClientStream(PipeDirection, String)

Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs
Source:
AnonymousPipeClientStream.cs

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

public AnonymousPipeClientStream(System.IO.Pipes.PipeDirection direction, string pipeHandleAsString);
[System.Security.SecurityCritical]
public AnonymousPipeClientStream(System.IO.Pipes.PipeDirection direction, string pipeHandleAsString);

Parameters

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

pipeHandleAsString
String

A string that represents the pipe handle.

Attributes

Exceptions

pipeHandleAsString is an invalid handle.

pipeHandleAsString is null.

direction is set to InOut.

Examples

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.

//<snippet01>
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]))
            {
                Console.WriteLine("[CLIENT] Current TransmissionMode: {0}.",
                   pipeClient.TransmissionMode);

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

                    // Wait for 'sync message' from the server.
                    do
                    {
                        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...");
        Console.ReadLine();
    }
}
//</snippet01>

Remarks

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1