AnonymousPipeClientStream::ReadMode Property

 

Sets the reading mode for the AnonymousPipeClientStream object.

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

public:
property PipeTransmissionMode ReadMode {
	[SecurityCriticalAttribute]
	virtual void set(PipeTransmissionMode value) override;
}

Exception Condition
ArgumentOutOfRangeException

The transmission mode is not valid. For anonymous pipes, only Byte is supported.

NotSupportedException

The transmission mode is Message.

IOException

The connection is broken or another I/O error occurs.

ObjectDisposedException

The pipe is closed.

Anonymous pipes do not support Message read mode.

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 AnonymousPipeClientStream object is created in a child process. The NotSupportedException is caught when the ReadMode property is set to Message.

#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]);
            // Show that anonymous Pipes do not support Message mode.
            try
            {
                Console::WriteLine("[CLIENT] Setting ReadMode to \"Message\".");
                pipeClient->ReadMode = PipeTransmissionMode::Message;
            }
            catch (NotSupportedException^ e)
            {
                Console::WriteLine("[CLIENT] Execption:\n    {0}", e->Message);
            }

            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);
}

.NET Framework
Available since 3.5
Return to top
Show: