共用方式為


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 不是有效的控制代碼。

safePipeHandlenull

direction 設定為 InOut

發生 I/O 錯誤,例如磁碟錯誤。

-或-

資料流已關閉。

範例

下列範例示範如何使用匿名管道,將字串從父進程傳送至子進程。 在此範例中,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

備註

PipeDirection不支援的值InOut,因為匿名管道會定義為單向。

適用於

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 不是有效的控制代碼。

pipeHandleAsStringnull

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>

備註

PipeDirection不支援的值InOut,因為匿名管道會定義為單向。

適用於