NamedPipeClientStream.NumberOfServerInstances Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar antalet serverinstanser som delar samma pipe-namn.
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
Egenskapsvärde
Antalet serverinstanser som delar samma pipe-namn.
- Attribut
Undantag
Rörhandtaget har inte ställts in.
-eller-
Det aktuella NamedPipeClientStream objektet har ännu inte anslutits till ett NamedPipeServerStream objekt.
Röret är trasigt eller så uppstod ett I/O-fel.
Det underliggande rörhandtaget är stängt.
Exempel
I följande exempel visas en metod för att skicka en sträng från en överordnad process till en underordnad process med hjälp av namngivna pipes. I det här exemplet skapas ett NamedPipeClientStream objekt i en underordnad process som sedan ansluter till ett rör på den lokala datorn. Serverexemplet kan visas i NamedPipeServerStream klassen. Det här exemplet är en del av ett större exempel som tillhandahålls för klasserna NamedPipeServerStream och NamedPipeClientStream .
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
Kommentarer
Den här egenskapen returnerar antalet serverinstanser för NamedPipeServerStream objektet som det aktuella NamedPipeClientStream objektet har ett handtag till eller är anslutet till. Om det aktuella NamedPipeClientStream objektet ännu inte har anslutit till en namngiven pipe-server, eller om det aktuella rörhandtaget ännu inte har angetts, genererar den här egenskapen en InvalidOperationException.