AnonymousPipeClientStream Конструкторы

Определение

Инициализирует новый экземпляр класса AnonymousPipeClientStream.

Перегрузки

AnonymousPipeClientStream(String)

Инициализирует новый экземпляр класса AnonymousPipeClientStream с использованием указанного дескриптора канала в строковом представлении.

AnonymousPipeClientStream(PipeDirection, SafePipeHandle)

Инициализирует новый экземпляр класса AnonymousPipeClientStream из указанного дескриптора.

AnonymousPipeClientStream(PipeDirection, String)

Инициализирует новый экземпляр класса AnonymousPipeClientStream с использованием указанного направления канала и строкового представления дескриптора канала.

AnonymousPipeClientStream(String)

Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs

Инициализирует новый экземпляр класса AnonymousPipeClientStream с использованием указанного дескриптора канала в строковом представлении.

public:
 AnonymousPipeClientStream(System::String ^ pipeHandleAsString);
public AnonymousPipeClientStream (string pipeHandleAsString);
new System.IO.Pipes.AnonymousPipeClientStream : string -> System.IO.Pipes.AnonymousPipeClientStream
Public Sub New (pipeHandleAsString As String)

Параметры

pipeHandleAsString
String

Строка, представляющая дескриптор канала.

Исключения

pipeHandleAsString не является допустимым дескриптором канала.

Примеры

В следующем примере демонстрируется способ отправки строки из родительского процесса в дочерний процесс с помощью анонимных каналов. В этом примере AnonymousPipeClientStream объект создается в дочернем процессе.

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();
    }
}
Imports System.IO
Imports System.IO.Pipes

Class PipeClient

    Shared Sub Main(ByVal args As String())
        If (args.Length > 0) Then

            Using pipeClient As 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 e As NotSupportedException
                    Console.WriteLine("EXCEPTION: {0}", e.Message)
                End Try

                Using sr As New StreamReader(pipeClient)

                    ' Display the read text to the console
                    Dim temp As String
                    temp = sr.ReadLine()
                    While Not temp = Nothing
                        Console.WriteLine(temp)
                        temp = sr.ReadLine()
                    End While
                End Using
            End Using
        End If
        Console.Write("Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class

Комментарии

Для конструкторов без PipeDirection параметра направление по умолчанию — In.

Применяется к

AnonymousPipeClientStream(PipeDirection, SafePipeHandle)

Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs

Инициализирует новый экземпляр класса AnonymousPipeClientStream из указанного дескриптора.

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

Параметры

direction
PipeDirection

Одно из значений перечисления, определяющее направление канала.

Данные в анонимных каналах могут передаваться только в одном направлении, поэтому для параметра direction нельзя задать значение InOut.

safePipeHandle
SafePipeHandle

Безопасный дескриптор для канала, который будет инкапсулироваться данным объектом AnonymousPipeClientStream.

Атрибуты

Исключения

safePipeHandle не является допустимым дескриптором.

safePipeHandle имеет значение null.

Параметру direction задается значение InOut.

Произошла ошибка ввода-вывода, например ошибка диска.

-или-

Поток закрыт.

Примеры

В следующем примере демонстрируется способ отправки строки из родительского процесса в дочерний процесс с помощью анонимных каналов. В этом примере AnonymousPipeClientStream объект создается в дочернем процессе со значением PipeDirectionIn.

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();
    }
}
Imports System.IO
Imports System.IO.Pipes

Class PipeClient

    Shared Sub Main(ByVal args As String())
        If (args.Length > 0) Then

            Using pipeClient As 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 e As NotSupportedException
                    Console.WriteLine("EXCEPTION: {0}", e.Message)
                End Try

                Using sr As New StreamReader(pipeClient)

                    ' Display the read text to the console
                    Dim temp As String
                    temp = sr.ReadLine()
                    While Not temp = Nothing
                        Console.WriteLine(temp)
                        temp = sr.ReadLine()
                    End While
                End Using
            End Using
        End If
        Console.Write("Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class

Комментарии

Значение PipeDirectionInOut не поддерживается, так как анонимные каналы определены как односторонние.

Применяется к

AnonymousPipeClientStream(PipeDirection, String)

Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs
Исходный код:
AnonymousPipeClientStream.cs

Инициализирует новый экземпляр класса AnonymousPipeClientStream с использованием указанного направления канала и строкового представления дескриптора канала.

public:
 AnonymousPipeClientStream(System::IO::Pipes::PipeDirection direction, System::String ^ pipeHandleAsString);
public AnonymousPipeClientStream (System.IO.Pipes.PipeDirection direction, string pipeHandleAsString);
[System.Security.SecurityCritical]
public AnonymousPipeClientStream (System.IO.Pipes.PipeDirection direction, string pipeHandleAsString);
new System.IO.Pipes.AnonymousPipeClientStream : System.IO.Pipes.PipeDirection * string -> System.IO.Pipes.AnonymousPipeClientStream
[<System.Security.SecurityCritical>]
new System.IO.Pipes.AnonymousPipeClientStream : System.IO.Pipes.PipeDirection * string -> System.IO.Pipes.AnonymousPipeClientStream
Public Sub New (direction As PipeDirection, pipeHandleAsString As String)

Параметры

direction
PipeDirection

Одно из значений перечисления, определяющее направление канала.

Данные в анонимных каналах могут передаваться только в одном направлении, поэтому для параметра direction нельзя задать значение InOut.

pipeHandleAsString
String

Строка, представляющая дескриптор канала.

Атрибуты

Исключения

pipeHandleAsString не является допустимым дескриптором.

pipeHandleAsString имеет значение null.

Параметру direction задается значение InOut.

Примеры

В следующем примере демонстрируется способ отправки строки из родительского процесса в дочерний процесс с помощью анонимных каналов. В этом примере AnonymousPipeClientStream объект создается в дочернем процессе со значением PipeDirectionIn.

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

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

ref class PipeClient
{
public:
    static void Main(array<String^>^ args)
    {
        if (args->Length > 1)
        {
            PipeStream^ pipeClient = gcnew AnonymousPipeClientStream(PipeDirection::In, args[1]);

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

            StreamReader^ sr = gcnew 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()) != nullptr)
            {
                Console::WriteLine("[CLIENT] Echo: " + temp);
            }
            sr->Close();
            pipeClient->Close();
        }
        Console::Write("[CLIENT] Press Enter to continue...");
        Console::ReadLine();
    }
};

int main()
{
    array<String^>^ args = Environment::GetCommandLineArgs();
    PipeClient::Main(args);
}
//</snippet01>
//<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>
'<snippet01>
Imports System.IO
Imports System.IO.Pipes

Class PipeClient
    Shared Sub Main(args() as String)
        If args.Length > 0 Then
            Using pipeClient As New AnonymousPipeClientStream(PipeDirection.In, args(0))
                Console.WriteLine("[CLIENT] Current TransmissionMode: {0}.", _
                   pipeClient.TransmissionMode)

                Using sr As New StreamReader(pipeClient)
                    ' Display the read text to the console
                    Dim temp As String

                    ' Wait for 'sync message' from the server.
                    Do
                        Console.WriteLine("[CLIENT] Wait for sync...")
                        temp = sr.ReadLine()
                    Loop While temp.StartsWith("SYNC") = False

                    ' Read the server data and echo to the console.
                    temp = sr.ReadLine()
                    While Not temp = Nothing
                        Console.WriteLine("[CLIENT] Echo: " + temp)
                        temp = sr.ReadLine()
                    End While
                End Using
            End Using
        End If
        Console.Write("[CLIENT] Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class
'</snippet01>

Комментарии

Значение PipeDirectionInOut не поддерживается, так как анонимные каналы определены как односторонние.

Применяется к