NamedPipeServerStream.WaitForConnection 메서드

정의

클라이언트가 이 NamedPipeServerStream 개체에 연결할 때까지 기다립니다.

public:
 void WaitForConnection();
public void WaitForConnection();
[System.Security.SecurityCritical]
public void WaitForConnection();
member this.WaitForConnection : unit -> unit
[<System.Security.SecurityCritical>]
member this.WaitForConnection : unit -> unit
Public Sub WaitForConnection ()
특성

예외

파이프 연결이 이미 설정되었습니다.

-또는-

파이프 핸들이 설정되지 않았습니다.

파이프가 닫혔습니다.

파이프 연결이 끊어졌습니다.

예제

다음 예제에서는 명명된 파이프를 사용하여 부모 프로세스에서 자식 프로세스로 문자열을 보내는 방법을 보여 줍니다. 다음은 부모 프로세스에서 NamedPipeServerStream 개체를 만드는 예제입니다. 이 개체의 값PipeDirectionOut 개체가 개체에 NamedPipeClientStream 대한 연결을 NamedPipeServerStream 설정할 때까지 차단합니다. 이 예제는 및 NamedPipeServerStream 클래스에 대해 제공되는 더 큰 예제의 NamedPipeClientStream 일부입니다.

using System;
using System.IO;
using System.IO.Pipes;

class PipeServer
{
    static void Main()
    {
        using (NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.Out))
        {
            Console.WriteLine("NamedPipeServerStream object created.");

            // Wait for a client to connect
            Console.Write("Waiting for client connection...");
            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected.");
            try
            {
                // Read user input and send that to the client process.
                using (StreamWriter sw = new StreamWriter(pipeServer))
                {
                    sw.AutoFlush = true;
                    Console.Write("Enter text: ");
                    sw.WriteLine(Console.ReadLine());
                }
            }
            // Catch the IOException that is raised if the pipe is broken
            // or disconnected.
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
        }
    }
}
Imports System.IO
Imports System.IO.Pipes

Class PipeServer

    Shared Sub Main()
        Dim pipeServer As New NamedPipeServerStream("testpipe", PipeDirection.Out)

        Console.WriteLine("NamedPipeServerStream object created.")

        ' Wait for a client to connect
        Console.Write("Waiting for a client connection...")
        pipeServer.WaitForConnection()

        Console.WriteLine("Client connected.")
        Try
            'Read user input and send that to the client process.
            Dim sw As New StreamWriter(pipeServer)
            sw.AutoFlush = True
            Console.Write("Enter Text: ")
            sw.WriteLine(Console.ReadLine())
        Catch ex As IOException
            ' Catch the IOException that is raised if the pipe is broken
            ' or disconnected
            Console.WriteLine("ERROR: {0}", ex.Message)
        End Try
    End Sub
End Class

설명

이 메서드를 호출하면 클라이언트가 NamedPipeServerStream 연결될 때까지 개체가 차단됩니다.

적용 대상