AnonymousPipeServerStream 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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()
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
初始化 AnonymousPipeServerStream 类的新实例。
public:
AnonymousPipeServerStream();
public AnonymousPipeServerStream ();
Public Sub New ()
注解
对于 AnonymousPipeServerStream 没有参数的 PipeDirection 构造函数,默认方向为 Out。 PipeDirection 不支持 值, InOut 因为匿名管道定义为单向管道。
此构造函数创建一个 AnonymousPipeServerStream 对象,该对象具有默认缓冲区大小、无管道安全性且 HandleInheritability 值为 None。
适用于
AnonymousPipeServerStream(PipeDirection)
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
- Source:
- 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
设置为 InOut。
注解
PipeDirection不支持 值,InOut因为匿名管道定义为单向管道。
此构造函数创建一个 AnonymousPipeServerStream 对象,该对象具有默认缓冲区大小、无管道安全性且 HandleInheritability 值为 None。
适用于
AnonymousPipeServerStream(PipeDirection, HandleInheritability)
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
- Source:
- 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)
参数
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。 必须设置为 None 或 Inheritable。
例外
未将 inheritability
设为 None 或 Inheritable。
将 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)
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
- Source:
- 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)
参数
- serverSafePipeHandle
- SafePipeHandle
此 AnonymousPipeServerStream 对象将封装的管道的安全句柄。
- clientSafePipeHandle
- SafePipeHandle
AnonymousPipeClientStream 对象的安全句柄。
- 属性
例外
serverSafePipeHandle
或 clientSafePipeHandle
是无效句柄。
serverSafePipeHandle
或 clientSafePipeHandle
为 null
。
将 direction
设置为 InOut。
注解
PipeDirection不支持 值,InOut因为匿名管道定义为单向管道。
适用于
AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)
- Source:
- AnonymousPipeServerStream.cs
- Source:
- AnonymousPipeServerStream.cs
- Source:
- 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)
参数
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。 必须设置为 None 或 Inheritable。
- bufferSize
- Int32
缓冲区的大小。 此值必须大于等于 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)
参数
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。
- bufferSize
- Int32
缓冲区的大小。 此值必须大于等于 0。
- pipeSecurity
- PipeSecurity
一个对象,确定管道的访问控制和审核安全性。
- 属性
例外
将 direction
设置为 InOut。
注解
PipeDirection不支持 值,InOut因为匿名管道定义为单向管道。