AnonymousPipeServerStream Constructor (PipeDirection, HandleInheritability)
Initializes a new instance of the AnonymousPipeServerStream class with the specified pipe direction and inheritability mode.
Assembly: System.Core (in System.Core.dll)
public:
AnonymousPipeServerStream(
PipeDirection direction,
HandleInheritability inheritability
)
Parameters
- direction
-
Type:
System.IO.Pipes::PipeDirection
One of the enumeration values that determines the direction of the pipe.
Anonymous pipes can only be in one direction, so direction cannot be set to InOut.
- inheritability
-
Type:
System.IO::HandleInheritability
One of the enumeration values that determines whether the underlying handle can be inherited by child processes. Must be set to either None or Inheritable.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | inheritability is not set to either None or Inheritable. |
| NotSupportedException | direction is set to InOut. |
A PipeDirection value of InOut is not supported because anonymous pipes are defined to be one-way.
This constructor creates an AnonymousPipeServerStream object that has the default buffer size and no pipe security.
The following example demonstrates a method to send a string from a parent process to a child process using anonymous pipes. In this example, an AnonymousPipeServerStream object is created in a parent process with a PipeDirection value of Out.
#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); // Show that anonymous pipes do not support Message mode. try { Console::WriteLine("[SERVER] Setting ReadMode to \"Message\"."); pipeServer->ReadMode = PipeTransmissionMode::Message; } catch (NotSupportedException^ e) { Console::WriteLine("[SERVER] Exception:\n {0}", e->Message); } 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(); }
for full trust for the immediate caller. This member cannot be used by partially trusted code.
Available since 3.5