AnonymousPipeServerStream 构造函数
定义
初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class.
重载
| AnonymousPipeServerStream() |
初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class. |
| AnonymousPipeServerStream(PipeDirection) |
使用指定的管道方向初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction. |
| AnonymousPipeServerStream(PipeDirection, HandleInheritability) |
使用指定的管道方向和继承模式初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction and inheritability mode. |
| AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle) |
从指定的管道句柄初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class from the specified pipe handles. |
| AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32) |
使用指定的管道方向、继承模式和缓冲区大小初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, and buffer size. |
| AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity) |
使用指定的管道方向、继承模式、缓冲区大小和管道安全性初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, buffer size, and pipe security. |
AnonymousPipeServerStream()
初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class.
public:
AnonymousPipeServerStream();
public AnonymousPipeServerStream ();
Public Sub New ()
注解
对于 AnonymousPipeServerStream 没有参数的构造函数 PipeDirection ,默认方向是 Out 。For AnonymousPipeServerStream constructors without a PipeDirection parameter, the default direction is Out. PipeDirection InOut 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
此构造函数将创建一个 AnonymousPipeServerStream 对象,该对象具有默认的缓冲区大小、管道安全性和 HandleInheritability 值 None 。This constructor creates an AnonymousPipeServerStream object that has the default buffer size, no pipe security, and a HandleInheritability value of None.
适用于
AnonymousPipeServerStream(PipeDirection)
使用指定的管道方向初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction.
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
确定管道方向的枚举值之一。One of the enumeration values that determines the direction of the pipe.
匿名管道只能是单向的,因此,direction 不能设置为 InOut。Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
例外
注解
PipeDirection InOut 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
此构造函数将创建一个 AnonymousPipeServerStream 对象,该对象具有默认的缓冲区大小、管道安全性和 HandleInheritability 值 None 。This constructor creates an AnonymousPipeServerStream object that has the default buffer size, no pipe security, and a HandleInheritability value of None.
适用于
AnonymousPipeServerStream(PipeDirection, HandleInheritability)
使用指定的管道方向和继承模式初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction and inheritability mode.
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
确定管道方向的枚举值之一。One of the enumeration values that determines the direction of the pipe.
匿名管道只能是单向的,因此,direction 不能设置为 InOut。Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。One of the enumeration values that determines whether the underlying handle can be inherited by child processes. 必须设置为 None 或 Inheritable。Must be set to either None or Inheritable.
例外
未将 inheritability 设为 None 或 Inheritable。inheritability is not set to either None or Inheritable.
示例
下面的示例演示了一个方法,该方法使用匿名管道将字符串从父进程发送到子进程。The following example demonstrates a method to send a string from a parent process to a child process using anonymous pipes. 在此示例中, AnonymousPipeServerStream 对象是在具有值的父进程中创建的 PipeDirection Out 。In this example, an AnonymousPipeServerStream object is created in a parent process with a PipeDirection value of 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 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
此构造函数将创建一个 AnonymousPipeServerStream 对象,该对象具有默认的缓冲区大小且没有管道安全性。This constructor creates an AnonymousPipeServerStream object that has the default buffer size and no pipe security.
适用于
AnonymousPipeServerStream(PipeDirection, SafePipeHandle, SafePipeHandle)
从指定的管道句柄初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class from the specified pipe handles.
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
确定管道方向的枚举值之一。One of the enumeration values that determines the direction of the pipe.
匿名管道只能是单向的,因此,direction 不能设置为 InOut。Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
- serverSafePipeHandle
- SafePipeHandle
此 AnonymousPipeServerStream 对象将封装的管道的安全句柄。A safe handle for the pipe that this AnonymousPipeServerStream object will encapsulate.
- clientSafePipeHandle
- SafePipeHandle
AnonymousPipeClientStream 对象的安全句柄。A safe handle for the AnonymousPipeClientStream object.
- 属性
例外
serverSafePipeHandle 或 clientSafePipeHandle 是无效句柄。serverSafePipeHandle or clientSafePipeHandle is an invalid handle.
serverSafePipeHandle 或 clientSafePipeHandle 为 null。serverSafePipeHandle or clientSafePipeHandle is null.
发生 I/O 错误,如磁盘错误。An I/O error, such as a disk error, has occurred.
- 或 --or-
已关闭流。The stream has been closed.
注解
PipeDirection InOut 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
适用于
AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32)
使用指定的管道方向、继承模式和缓冲区大小初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, and buffer size.
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
确定管道方向的枚举值之一。One of the enumeration values that determines the direction of the pipe.
匿名管道只能是单向的,因此,direction 不能设置为 InOut。Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。One of the enumeration values that determines whether the underlying handle can be inherited by child processes. 必须设置为 None 或 Inheritable。Must be set to either None or Inheritable.
- bufferSize
- Int32
缓冲区的大小。The size of the buffer. 此值必须大于等于 0。This value must be greater than or equal to 0.
- 属性
例外
未将 inheritability 设为 None 或 Inheritable。inheritability is not set to either None or Inheritable.
- 或 --or-
bufferSize 小于 0。bufferSize is less than 0.
注解
PipeDirection InOut 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
此构造函数创建一个 AnonymousPipeServerStream 没有管道安全性的对象。This constructor creates an AnonymousPipeServerStream object without pipe security.
适用于
AnonymousPipeServerStream(PipeDirection, HandleInheritability, Int32, PipeSecurity)
使用指定的管道方向、继承模式、缓冲区大小和管道安全性初始化 AnonymousPipeServerStream 类的新实例。Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction, inheritability mode, buffer size, and pipe security.
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
确定管道方向的枚举值之一。One of the enumeration values that determines the direction of the pipe.
匿名管道只能是单向的,因此,direction 不能设置为 InOut。Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
- inheritability
- HandleInheritability
确定基础句柄能否由子进程继承的枚举值之一。One of the enumeration values that determines whether the underlying handle can be inherited by child processes.
- bufferSize
- Int32
缓冲区的大小。The size of the buffer. 此值必须大于等于 0。This value must be greater than or equal to 0.
- pipeSecurity
- PipeSecurity
一个对象,确定管道的访问控制和审核安全性。An object that determines the access control and audit security for the pipe.
- 属性
例外
未将 inheritability 设为 None 或 Inheritable。inheritability is not set to either None or Inheritable.
- 或 --or-
bufferSize 小于 0。bufferSize is less than 0.
注解
PipeDirection InOut 不支持的值,因为匿名管道定义为单向。A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.