D
dgk
I trying to use a named pipe but can't figure out how to get the
callback to work:
Module Module1
Private ps As System.IO.Pipes.NamedPipeServerStream
Public Sub main()
Application.EnableVisualStyles()
Try
ps = New System.IO.Pipes.NamedPipeServerStream("Test")
ps.BeginWaitForConnection(AddressOf HandleConnection, "Test")
Catch ex As Exception
' pipe already exists
End Try
Application.Run(Form1)
End Sub
Public Sub HandleConnection(ByVal ar As System.IAsyncResult)
ps.EndWaitForConnection(ar)
Using sr As New System.IO.StreamReader(ps)
Dim message As String = ""
Do
message = sr.ReadLine
Console.WriteLine(message)
Loop While message IsNot Nothing
End Using
End Sub
End Module
I don't understand what the second parameter (object) is doing on the
BeginWaitForConnection. Maybe because of that, and maybe not,
HandleConnection doesn't ever fire, even when another program does
open the pipe Test. Nor do I understand why I need to call
EndWaitForConnection (maybe I don't need to?), or what to do with the
IAsyncResut.
Any info greatly appreciated.
callback to work:
Module Module1
Private ps As System.IO.Pipes.NamedPipeServerStream
Public Sub main()
Application.EnableVisualStyles()
Try
ps = New System.IO.Pipes.NamedPipeServerStream("Test")
ps.BeginWaitForConnection(AddressOf HandleConnection, "Test")
Catch ex As Exception
' pipe already exists
End Try
Application.Run(Form1)
End Sub
Public Sub HandleConnection(ByVal ar As System.IAsyncResult)
ps.EndWaitForConnection(ar)
Using sr As New System.IO.StreamReader(ps)
Dim message As String = ""
Do
message = sr.ReadLine
Console.WriteLine(message)
Loop While message IsNot Nothing
End Using
End Sub
End Module
I don't understand what the second parameter (object) is doing on the
BeginWaitForConnection. Maybe because of that, and maybe not,
HandleConnection doesn't ever fire, even when another program does
open the pipe Test. Nor do I understand why I need to call
EndWaitForConnection (maybe I don't need to?), or what to do with the
IAsyncResut.
Any info greatly appreciated.