共用方式為


AnonymousPipeServerStream 建構函式

定義

初始化 AnonymousPipeServerStream 類別的新執行個體。

多載

AnonymousPipeServerStream()

初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream(PipeDirection)

使用指定的管道方向,初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream(PipeDirection, HandleInheritability)

使用指定的管道方向與繼承模式,初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle)

從指定的管道控制碼初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)

使用指定的管道方向、繼承模式及緩衝區大小,初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity)

使用指定的管道方向、繼承模式、緩衝區大小及管道安全性,初始化 AnonymousPipeServerStream 類別的新執行個體。

AnonymousPipeServerStream()

來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs

初始化 AnonymousPipeServerStream 類別的新執行個體。

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

備註

對於 AnonymousPipeServerStream 不含參數的 PipeDirection 建構函式,預設方向為 OutPipeDirection 不支援的值 InOut ,因為匿名管道會定義為單向。

此建構函式會建立具有 AnonymousPipeServerStream 默認緩衝區大小、無管道安全性及 HandleInheritability 值的物件 None

適用於

AnonymousPipeServerStream(PipeDirection)

來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs

使用指定的管道方向,初始化 AnonymousPipeServerStream 類別的新執行個體。

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)

參數

direction
PipeDirection

其中一個列舉值,決定管道的方向。

因為匿名管線只能用於單一方向,所以 direction 無法設定為 InOut

例外狀況

direction 設定為 InOut

備註

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

此建構函式會建立具有 AnonymousPipeServerStream 默認緩衝區大小、無管道安全性及 HandleInheritability 值的物件 None

適用於

AnonymousPipeServerStream(PipeDirection, HandleInheritability)

來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs

使用指定的管道方向與繼承模式,初始化 AnonymousPipeServerStream 類別的新執行個體。

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)

參數

direction
PipeDirection

其中一個列舉值,決定管道的方向。

因為匿名管線只能用於單一方向,所以 direction 無法設定為 InOut

inheritability
HandleInheritability

其中一個列舉值,決定子處理序是否可以繼承基礎控制代碼。 必須設定為 NoneInheritable

例外狀況

inheritability 不是設定為 NoneInheritable

direction 設定為 InOut

範例

下列範例示範使用匿名管道將字串從父進程傳送至子進程的方法。 在這裡範例中, AnonymousPipeServerStream 物件會在父進程中建立,其 PipeDirection 值為 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>

備註

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

此建構函式會建立具有 AnonymousPipeServerStream 默認緩衝區大小且沒有管道安全性的物件。

適用於

AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle)

來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs

從指定的管道控制碼初始化 AnonymousPipeServerStream 類別的新執行個體。

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)

參數

direction
PipeDirection

其中一個列舉值,決定管道的方向。

因為匿名管線只能用於單一方向,所以 direction 無法設定為 InOut

serverSafePipeHandle
SafePipeHandle

安全控制代碼,用於這個 AnonymousPipeServerStream 物件將會封裝的管道。

clientSafePipeHandle
SafePipeHandle

AnonymousPipeClientStream 物件的安全控制代碼。

屬性

例外狀況

serverSafePipeHandleclientSafePipeHandle 是無效的控制代碼。

serverSafePipeHandleclientSafePipeHandlenull

direction 設定為 InOut

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

-或-

資料流已關閉。

備註

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

適用於

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)

來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs
來源:
AnonymousPipeServerStream.cs

使用指定的管道方向、繼承模式及緩衝區大小,初始化 AnonymousPipeServerStream 類別的新執行個體。

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)

參數

direction
PipeDirection

其中一個列舉值,決定管道的方向。

因為匿名管線只能用於單一方向,所以 direction 無法設定為 InOut

inheritability
HandleInheritability

其中一個列舉值,決定子處理序是否可以繼承基礎控制代碼。 必須設定為 NoneInheritable

bufferSize
Int32

緩衝區的大小。 這個值必須大於或等於 0。

屬性

例外狀況

inheritability 不是設定為 NoneInheritable

-或-

bufferSize 小於 0。

direction 設定為 InOut

備註

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

此建 AnonymousPipeServerStream 構函式會建立不含管道安全性的物件。

適用於

AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity)

使用指定的管道方向、繼承模式、緩衝區大小及管道安全性,初始化 AnonymousPipeServerStream 類別的新執行個體。

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)

參數

direction
PipeDirection

其中一個列舉值,決定管道的方向。

因為匿名管線只能用於單一方向,所以 direction 無法設定為 InOut

inheritability
HandleInheritability

其中一個列舉值,決定子處理序是否可以繼承基礎控制代碼。

bufferSize
Int32

緩衝區的大小。 這個值必須大於或等於 0。

pipeSecurity
PipeSecurity

物件,判斷管道的存取控制和稽核安全性。

屬性

例外狀況

inheritability 不是設定為 NoneInheritable

-或-

bufferSize 小於 0。

direction 設定為 InOut

備註

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

適用於