PC Review


Reply
Thread Tools Rate Thread

Callback on Named Pipe question

 
 
dgk
Guest
Posts: n/a
 
      27th Dec 2007
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.
 
Reply With Quote
 
 
 
 
dgk
Guest
Posts: n/a
 
      27th Dec 2007
On Thu, 27 Dec 2007 10:41:34 -0500, dgk <(E-Mail Removed)> wrote:

>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.



Ok, I get to answer my own question. If you want to use async methods
with named pipes, you need to open the pipe as async:

ps = New System.IO.Pipes.NamedPipeServerStream("Test",
IO.Pipes.PipeDirection.InOut, 3,
IO.Pipes.PipeTransmissionMode.Message,
IO.Pipes.PipeOptions.Asynchronous)
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Named pipe question! DBC User Microsoft C# .NET 0 10th Dec 2007 10:16 PM
A question about Named Pipe? Nick Microsoft C# .NET 0 21st Oct 2005 12:51 AM
Unable to impersonate via a named pipe until data has been read from that pipe Greg Microsoft Windows 2000 Networking 0 20th Dec 2003 12:51 AM
Unable to impersonate via a named pipe until data has been read from that pipe =?Utf-8?B?anVuaW9yaW50ZXJu?= Microsoft Windows 2000 0 21st Oct 2003 08:41 PM
Re: Named Pipe Kumar Gaurav Khanna [.NET MVP] Microsoft C# .NET 0 1st Sep 2003 03:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:55 PM.