AnonymousPipeClientStream 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
公开匿名管道流的客户端,该流支持同步和异步读取和写入操作(在 Windows 平台上不受取消支持)。
public ref class AnonymousPipeClientStream sealed : System::IO::Pipes::PipeStream
	public sealed class AnonymousPipeClientStream : System.IO.Pipes.PipeStream
	type AnonymousPipeClientStream = class
    inherit PipeStream
	Public NotInheritable Class AnonymousPipeClientStream
Inherits PipeStream
		- 继承
 
- 继承
 
示例
以下示例使用匿名管道将父进程中的字符串发送到子进程。 此示例在父进程中创建一个 AnonymousPipeServerStream 对象,其 PipeDirection 值为 Out。它还在子进程中创建一个 AnonymousPipeClientStream 对象,其 PipeDirection 值为 In。 然后,父进程将用户提供的字符串发送到子进程。 字符串会显示到控制台。
此示例适用于由服务器进程启动的客户端进程。 将生成的可执行文件命名为客户端代码 pipeClient.exe,并在运行此示例时将其复制到与服务器可执行文件相同的目录。 有关整个代码示例(包括管道客户端和服务器的代码)请参阅 如何:使用匿名管道进行本地进程间通信。
//<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>
	注解
匿名管道有助于在子进程和父进程之间提供安全可靠的进程间通信。 AnonymousPipeClientStream 类使子进程能够连接到父进程并与父进程交换信息。
匿名管道是未命名的单向管道,通常在父进程和子进程之间传输数据。 匿名管道始终是本地管道;不能通过网络使用它们。 不支持 InOutPipeDirection 值,因为匿名管道定义为单向管道。
匿名管道不支持 PipeTransmissionMode.Message 读取模式。
匿名管道的客户端必须通过调用 GetClientHandleAsString 方法从服务器端提供的管道句柄创建。 然后,在创建客户端进程时将字符串作为参数传递。 在客户端进程中,它将作为 pipeHandleAsString 参数传递给 AnonymousPipeClientStream 构造函数。
在 Windows 上,匿名管道不支持异步(重叠)读取和写入操作(请参阅 匿名管道操作)。 AnonymousPipeClientStream 类仍将在 Windows 平台上的线程池上安排工作,因此异步 Stream 操作有效,但不支持取消这些操作。
构造函数
| AnonymousPipeClientStream(PipeDirection, SafePipeHandle) | 
		 从指定的句柄初始化 AnonymousPipeClientStream 类的新实例。  | 
        	
| AnonymousPipeClientStream(PipeDirection, String) | 
		 使用指定的管道方向和管道句柄的字符串表示形式初始化 AnonymousPipeClientStream 类的新实例。  | 
        	
| AnonymousPipeClientStream(String) | 
		 使用管道句柄的指定字符串表示形式初始化 AnonymousPipeClientStream 类的新实例。  | 
        	
属性
| CanRead | 
		 获取一个值,该值指示当前流是否支持读取操作。 (继承自 PipeStream) | 
        	
| CanSeek | 
		 获取一个值,该值指示当前流是否支持查找操作。 (继承自 PipeStream) | 
        	
| CanTimeout | 
		 获取一个值,该值确定当前流是否可以超时。 (继承自 Stream) | 
        	
| CanWrite | 
		 获取一个值,该值指示当前流是否支持写入操作。 (继承自 PipeStream) | 
        	
| InBufferSize | 
		 获取管道的入站缓冲区的大小(以字节为单位)。 (继承自 PipeStream) | 
        	
| IsAsync | 
		 获取一个值,该值指示 PipeStream 对象是异步打开还是同步打开。 (继承自 PipeStream) | 
        	
| IsConnected | 
		 获取或设置一个值,该值指示 PipeStream 对象是否已连接。 (继承自 PipeStream) | 
        	
| IsHandleExposed | 
		 获取一个值,该值指示是否公开 PipeStream 对象的句柄。 (继承自 PipeStream) | 
        	
| IsMessageComplete | 
		 获取一个值,该值指示从最近的读取操作返回的消息中是否有更多数据。 (继承自 PipeStream) | 
        	
| Length | 
		 获取流的长度(以字节为单位)。 (继承自 PipeStream) | 
        	
| OutBufferSize | 
		 获取管道的出站缓冲区的大小(以字节为单位)。 (继承自 PipeStream) | 
        	
| Position | 
		 获取或设置当前流的当前位置。 (继承自 PipeStream) | 
        	
| ReadMode | 
		 设置 AnonymousPipeClientStream 对象的读取模式。  | 
        	
| ReadTimeout | 
		 获取或设置一个值(以毫秒为单位),该值确定流在超时前尝试读取的时间。 (继承自 Stream) | 
        	
| SafePipeHandle | 
		 获取当前 PipeStream 对象封装的管道的本地端的安全句柄。 (继承自 PipeStream) | 
        	
| TransmissionMode | 
		 获取当前管道支持的管道传输模式。  | 
        	
| WriteTimeout | 
		 获取或设置一个值(以毫秒为单位),该值确定流在超时之前尝试写入的时间。 (继承自 Stream) | 
        	
方法
扩展方法
| CopyToAsync(Stream, PipeWriter, CancellationToken) | 
		 使用取消令牌从 Stream 异步读取字节并将其写入指定的 PipeWriter。  | 
        	
| GetAccessControl(PipeStream) | 
		 返回管道流的安全信息。  | 
        	
| SetAccessControl(PipeStream, PipeSecurity) | 
		 更改现有管道流的安全属性。  | 
        	
| ConfigureAwait(IAsyncDisposable, Boolean) | 
		 配置如何执行从异步可释放项返回的任务的 await。  |