Share via


NamedPipeClientStream.NumberOfServerInstances 속성

정의

같은 파이프 이름을 공유하는 서버 인스턴스의 수를 가져옵니다.

public:
 property int NumberOfServerInstances { int get(); };
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public int NumberOfServerInstances { get; }
public int NumberOfServerInstances { get; }
public int NumberOfServerInstances { [System.Security.SecurityCritical] get; }
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.NumberOfServerInstances : int
member this.NumberOfServerInstances : int
[<get: System.Security.SecurityCritical>]
member this.NumberOfServerInstances : int
Public ReadOnly Property NumberOfServerInstances As Integer

속성 값

같은 파이프 이름을 공유하는 서버 인스턴스의 수입니다.

특성

예외

파이프 핸들이 설정되지 않은 경우

또는

현재 NamedPipeClientStream 개체가 아직 NamedPipeServerStream 개체에 연결되지 않은 경우

파이프가 끊어졌거나 I/O 오류가 발생한 경우

내부 파이프 핸들이 닫혔습니다.

예제

다음 예제에서는 명명된 파이프를 사용하여 부모 프로세스에서 자식 프로세스로 문자열을 보내는 메서드를 보여 줍니다. 이 예제에서는 NamedPipeClientStream 자식 프로세스에서 개체를 만든 다음 로컬 컴퓨터의 파이프에 연결합니다. 서버 예제는 클래스에서 NamedPipeServerStream 볼 수 있습니다. 이 예제는 및 NamedPipeClientStream 클래스에 대해 제공되는 더 큰 예제의 NamedPipeServerStream 일부입니다.

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

class PipeClient
{
    static void Main(string[] args)
    {
        using (NamedPipeClientStream pipeClient =
            new NamedPipeClientStream(".", "testpipe", PipeDirection.In))
        {

            // Connect to the pipe or wait until the pipe is available.
            Console.Write("Attempting to connect to pipe...");
            pipeClient.Connect();

            Console.WriteLine("Connected to pipe.");
            Console.WriteLine("There are currently {0} pipe server instances open.",
               pipeClient.NumberOfServerInstances);
            using (StreamReader sr = new StreamReader(pipeClient))
            {
                // Display the read text to the console
                string temp;
                while ((temp = sr.ReadLine()) != null)
                {
                    Console.WriteLine("Received from server: {0}", temp);
                }
            }
        }
        Console.Write("Press Enter to continue...");
        Console.ReadLine();
    }
}
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal

Class PipeClient

    Shared Sub Main(ByVal args As String())

        Dim pipeClient As New NamedPipeClientStream("localhost", _
                    "testpipe", PipeDirection.In, PipeOptions.None)

        ' Connect to the pipe or wait until the pipe is available.
        Console.WriteLine("Attempting to connect to the pipe...")
        pipeClient.Connect()

        Console.WriteLine("Connect to the pipe.")
        Console.WriteLine("There are currently {0} pipe server instances open.", _
                          pipeClient.NumberOfServerInstances)

        Dim sr As New StreamReader(pipeClient)
        Dim temp As String

        temp = sr.ReadLine()
        While Not temp Is Nothing
            Console.WriteLine("Received from server: {0}", temp)
            temp = sr.ReadLine()
        End While
        Console.Write("Press Enter to continue...")
        Console.ReadLine()
    End Sub
End Class

설명

이 속성은 현재 NamedPipeClientStream 개체에 대한 핸들이 있거나 연결된 개체의 서버 인스턴스 NamedPipeServerStream 수를 반환합니다. 현재 NamedPipeClientStream 개체가 명명된 파이프 서버에 아직 연결되지 않았거나 현재 파이프 핸들이 아직 설정되지 않은 경우 이 속성은 을 InvalidOperationExceptionthrow합니다.

적용 대상