I create a thread which creates three new threads with a named pipe server in each thread.
serverThread = New Thread(AddressOf enableClientRequests) serverThread.Start() .... Friend Sub enableClientRequests() Dim i As Integer For i = 0 To OptMaxConcurrentClients - 1 managerIFlist(i) = New clsPhotExManagerInterface servers(i) = New Thread(AddressOf managerIFlist(i).server) servers(i).Start() Next i Thread.Sleep(250) While i > 0 For j As Integer = 0 To OptMaxConcurrentClients - 1 If Not (servers(j) Is Nothing) Then If servers(j).Join(250) Then servers(j) = Nothing i -= 1 ' decrement the thread watch count End If End If Next j End While End Sub ... Public Class clsPhotExManagerInterface #Region "PhotExPackage requests" Private pipeServer As NamedPipeServerStream Public Sub server() pipeServer = New NamedPipeServerStream("PhotExPipe", PipeDirection.InOut, OptMaxConcurrentClients) Do pipeServer.WaitForConnection() ... do work pipeServer.Disconnect() Loop End Sub Public Sub serverClose() pipeServer.Close() End Sub
When I want to stop accepting request, and in the Application.close event, I close them all down....
Private Sub closePackageServer() If serverThread IsNot Nothing Then For j As Integer = 0 To OptMaxConcurrentClients - 1 managerIFlist(j).serverClose() If servers(j) IsNot Nothing Then servers(j).Abort() servers(j) = Nothing managerIFlist(j) = Nothing End If Next j serverThread.Abort() End If End Sub
This invokes the serverClose method on all three threads but the application does not close. Clicking Pause in Visual Studio
shows the code ay the pipeServer.WaitForConnection statement.
How can I close it?