Edit

Share via


AnonymousPipeServerStream Constructors

Definition

Initializes a new instance of the AnonymousPipeServerStream class.

Overloads

AnonymousPipeServerStream()

Initializes a new instance of the AnonymousPipeServerStream class.

AnonymousPipeServerStream(PipeDirection)

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction.

AnonymousPipeServerStream(PipeDirection, HandleInheritability)

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction and inheritability mode.

AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle)

Initializes a new instance of the AnonymousPipeServerStream class from the specified pipe handles.

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, and buffer size.

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity)

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, buffer size, and pipe security.

AnonymousPipeServerStream()

Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs

Initializes a new instance of the AnonymousPipeServerStream class.

public:
 AnonymousPipeServerStream();
public AnonymousPipeServerStream ();
Public Sub New ()

Remarks

For AnonymousPipeServerStream constructors without a PipeDirection parameter, the default direction is Out. A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.

This constructor creates an AnonymousPipeServerStream object that has the default buffer size, no pipe security, and a HandleInheritability value of None.

Applies to

AnonymousPipeServerStream(PipeDirection)

Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction.

public:
 AnonymousPipeServerStream(System::IO::Pipes::PipeDirection direction);
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction);
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection -> System.IO.Pipes.AnonymousPipeServerStream
Public Sub New (direction As PipeDirection)

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.

Exceptions

direction is set to InOut.

Remarks

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

This constructor creates an AnonymousPipeServerStream object that has the default buffer size, no pipe security, and a HandleInheritability value of None.

Applies to

AnonymousPipeServerStream(PipeDirection, HandleInheritability)

Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction and inheritability mode.

public:
 AnonymousPipeServerStream(System::IO::Pipes::PipeDirection direction, System::IO::HandleInheritability inheritability);
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability);
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * System.IO.HandleInheritability -> System.IO.Pipes.AnonymousPipeServerStream
Public Sub New (direction As PipeDirection, inheritability As HandleInheritability)

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.

inheritability
HandleInheritability

One of the enumeration values that determines whether the underlying handle can be inherited by child processes. Must be set to either None or Inheritable.

Exceptions

inheritability is not set to either None or Inheritable.

direction is set to InOut.

Examples

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

//<snippet01>
#using <System.dll>
#using <System.Core.dll>

using namespace System;
using namespace System::IO;
using namespace System::IO::Pipes;
using namespace System::Diagnostics;

ref class PipeServer
{
public:
    static void Main()
    {
        Process^ pipeClient = gcnew Process();

        pipeClient->StartInfo->FileName = "pipeClient.exe";

        AnonymousPipeServerStream^ pipeServer =
            gcnew AnonymousPipeServerStream(PipeDirection::Out,
            HandleInheritability::Inheritable);

        Console::WriteLine("[SERVER] Current TransmissionMode: {0}.",
            pipeServer->TransmissionMode);

        // Pass the client process a handle to the server.
        pipeClient->StartInfo->Arguments =
            pipeServer->GetClientHandleAsString();
        pipeClient->StartInfo->UseShellExecute = false;
        pipeClient->Start();

        pipeServer->DisposeLocalCopyOfClientHandle();

        try
        {
            // Read user input and send that to the client process.
            StreamWriter^ sw = gcnew StreamWriter(pipeServer);

            sw->AutoFlush = true;
            // Send a 'sync message' and wait for client to receive it.
            sw->WriteLine("SYNC");
            pipeServer->WaitForPipeDrain();
            // Send the console input to the client process.
            Console::Write("[SERVER] Enter text: ");
            sw->WriteLine(Console::ReadLine());
            sw->Close();
        }
        // Catch the IOException that is raised if the pipe is broken
        // or disconnected.
        catch (IOException^ e)
        {
            Console::WriteLine("[SERVER] Error: {0}", e->Message);
        }
        pipeServer->Close();
        pipeClient->WaitForExit();
        pipeClient->Close();
        Console::WriteLine("[SERVER] Client quit. Server terminating.");
    }
};

int main()
{
    PipeServer::Main();
}
//</snippet01>
//<snippet01>
using System;
using System.IO;
using System.IO.Pipes;
using System.Diagnostics;

class PipeServer
{
    static void Main()
    {
        Process pipeClient = new Process();

        pipeClient.StartInfo.FileName = "pipeClient.exe";

        using (AnonymousPipeServerStream pipeServer =
            new AnonymousPipeServerStream(PipeDirection.Out,
            HandleInheritability.Inheritable))
        {
            Console.WriteLine("[SERVER] Current TransmissionMode: {0}.",
                pipeServer.TransmissionMode);

            // Pass the client process a handle to the server.
            pipeClient.StartInfo.Arguments =
                pipeServer.GetClientHandleAsString();
            pipeClient.StartInfo.UseShellExecute = false;
            pipeClient.Start();

            pipeServer.DisposeLocalCopyOfClientHandle();

            try
            {
                // Read user input and send that to the client process.
                using (StreamWriter sw = new StreamWriter(pipeServer))
                {
                    sw.AutoFlush = true;
                    // Send a 'sync message' and wait for client to receive it.
                    sw.WriteLine("SYNC");
                    pipeServer.WaitForPipeDrain();
                    // Send the console input to the client process.
                    Console.Write("[SERVER] Enter text: ");
                    sw.WriteLine(Console.ReadLine());
                }
            }
            // Catch the IOException that is raised if the pipe is broken
            // or disconnected.
            catch (IOException e)
            {
                Console.WriteLine("[SERVER] Error: {0}", e.Message);
            }
        }

        pipeClient.WaitForExit();
        pipeClient.Close();
        Console.WriteLine("[SERVER] Client quit. Server terminating.");
    }
}
//</snippet01>
'<snippet01>
Imports System.IO
Imports System.IO.Pipes
Imports System.Diagnostics

Class PipeServer
    Shared Sub Main()
        Dim pipeClient As New Process()

        pipeClient.StartInfo.FileName = "pipeClient.exe"

        Using pipeServer As New AnonymousPipeServerStream(PipeDirection.Out, _
            HandleInheritability.Inheritable)

            Console.WriteLine("[SERVER] Current TransmissionMode: {0}.",
                pipeServer.TransmissionMode)

            ' Pass the client process a handle to the server.
            pipeClient.StartInfo.Arguments = pipeServer.GetClientHandleAsString()
            pipeClient.StartInfo.UseShellExecute = false
            pipeClient.Start()

            pipeServer.DisposeLocalCopyOfClientHandle()

            Try
                ' Read user input and send that to the client process.
                Using sw As New StreamWriter(pipeServer)
                    sw.AutoFlush = true
                    ' Send a 'sync message' and wait for client to receive it.
                    sw.WriteLine("SYNC")
                    pipeServer.WaitForPipeDrain()
                    ' Send the console input to the client process.
                    Console.Write("[SERVER] Enter text: ")
                    sw.WriteLine(Console.ReadLine())
                End Using
            Catch e As IOException
                ' Catch the IOException that is raised if the pipe is broken
                ' or disconnected.
                Console.WriteLine("[SERVER] Error: {0}", e.Message)
            End Try
        End Using

        pipeClient.WaitForExit()
        pipeClient.Close()
        Console.WriteLine("[SERVER] Client quit. Server terminating.")
    End Sub
End Class
'</snippet01>

Remarks

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

This constructor creates an AnonymousPipeServerStream object that has the default buffer size and no pipe security.

Applies to

AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle)

Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs

Initializes a new instance of the AnonymousPipeServerStream class from the specified pipe handles.

public:
 AnonymousPipeServerStream(System::IO::Pipes::PipeDirection direction, Microsoft::Win32::SafeHandles::SafePipeHandle ^ serverSafePipeHandle, Microsoft::Win32::SafeHandles::SafePipeHandle ^ clientSafePipeHandle);
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, Microsoft.Win32.SafeHandles.SafePipeHandle serverSafePipeHandle, Microsoft.Win32.SafeHandles.SafePipeHandle clientSafePipeHandle);
[System.Security.SecurityCritical]
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, Microsoft.Win32.SafeHandles.SafePipeHandle serverSafePipeHandle, Microsoft.Win32.SafeHandles.SafePipeHandle clientSafePipeHandle);
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * Microsoft.Win32.SafeHandles.SafePipeHandle * Microsoft.Win32.SafeHandles.SafePipeHandle -> System.IO.Pipes.AnonymousPipeServerStream
[<System.Security.SecurityCritical>]
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * Microsoft.Win32.SafeHandles.SafePipeHandle * Microsoft.Win32.SafeHandles.SafePipeHandle -> System.IO.Pipes.AnonymousPipeServerStream
Public Sub New (direction As PipeDirection, serverSafePipeHandle As SafePipeHandle, clientSafePipeHandle As 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.

serverSafePipeHandle
SafePipeHandle

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

clientSafePipeHandle
SafePipeHandle

A safe handle for the AnonymousPipeClientStream object.

Attributes

Exceptions

serverSafePipeHandle or clientSafePipeHandle is an invalid handle.

serverSafePipeHandle or clientSafePipeHandle is null.

direction is set to InOut.

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

-or-

The stream has been closed.

Remarks

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

Applies to

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)

Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs
Source:
AnonymousPipeServerStream.cs

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, and buffer size.

public:
 AnonymousPipeServerStream(System::IO::Pipes::PipeDirection direction, System::IO::HandleInheritability inheritability, int bufferSize);
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize);
[System.Security.SecurityCritical]
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize);
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * System.IO.HandleInheritability * int -> System.IO.Pipes.AnonymousPipeServerStream
[<System.Security.SecurityCritical>]
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * System.IO.HandleInheritability * int -> System.IO.Pipes.AnonymousPipeServerStream
Public Sub New (direction As PipeDirection, inheritability As HandleInheritability, bufferSize As Integer)

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.

inheritability
HandleInheritability

One of the enumeration values that determines whether the underlying handle can be inherited by child processes. Must be set to either None or Inheritable.

bufferSize
Int32

The size of the buffer. This value must be greater than or equal to 0.

Attributes

Exceptions

inheritability is not set to either None or Inheritable.

-or-

bufferSize is less than 0.

direction is set to InOut.

Remarks

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

This constructor creates an AnonymousPipeServerStream object without pipe security.

Applies to

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity)

Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, buffer size, and pipe security.

public:
 AnonymousPipeServerStream(System::IO::Pipes::PipeDirection direction, System::IO::HandleInheritability inheritability, int bufferSize, System::IO::Pipes::PipeSecurity ^ pipeSecurity);
[System.Security.SecurityCritical]
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize, System.IO.Pipes.PipeSecurity pipeSecurity);
public AnonymousPipeServerStream (System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize, System.IO.Pipes.PipeSecurity pipeSecurity);
[<System.Security.SecurityCritical>]
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * System.IO.HandleInheritability * int * System.IO.Pipes.PipeSecurity -> System.IO.Pipes.AnonymousPipeServerStream
new System.IO.Pipes.AnonymousPipeServerStream : System.IO.Pipes.PipeDirection * System.IO.HandleInheritability * int * System.IO.Pipes.PipeSecurity -> System.IO.Pipes.AnonymousPipeServerStream
Public Sub New (direction As PipeDirection, inheritability As HandleInheritability, bufferSize As Integer, pipeSecurity As PipeSecurity)

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.

inheritability
HandleInheritability

One of the enumeration values that determines whether the underlying handle can be inherited by child processes.

bufferSize
Int32

The size of the buffer. This value must be greater than or equal to 0.

pipeSecurity
PipeSecurity

An object that determines the access control and audit security for the pipe.

Attributes

Exceptions

inheritability is not set to either None or Inheritable.

-or-

bufferSize is less than 0.

direction is set to InOut.

Remarks

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

Applies to