Export (0) Print
Expand All

AnonymousPipeServerStream.DisposeLocalCopyOfClientHandle Method

Closes the local copy of the AnonymousPipeClientStream object's handle.

Namespace:  System.IO.Pipes
Assembly:  System.Core (in System.Core.dll)

public void DisposeLocalCopyOfClientHandle()

The DisposeLocalCopyOfClientHandle method should be called after the client handle has been passed to the client. If this method is not called, the AnonymousPipeServerStream object will not receive notice when the client disposes of its PipeStream object.

The following example demonstrates a way to send a string from a parent process to a child process by using anonymous pipes. In this example, an AnonymousPipeServerStream object is created in a parent process with a PipeDirection value of Out.

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,
            // Show that anonymous pipes do not support Message mode. 
                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}.",

            // Pass the client process a handle to the server.
            pipeClient.StartInfo.Arguments =
            pipeClient.StartInfo.UseShellExecute = false;


                // 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.
                    // Send the console input to the client process.
                    Console.Write("[SERVER] Enter text: ");
            // Catch the IOException that is raised if the pipe is broken 
            // or disconnected. 
            catch (IOException e)
                Console.WriteLine("[SERVER] Error: {0}", e.Message);

        Console.WriteLine("[SERVER] Client quit. Server terminating.");

.NET Framework

Supported in: 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft