System.IO.Pipes.NamedPipeClientStream.Connect

A

AMercer

When a client thread calls Connect, it blocks until the connection is made.
If the server is busy, the client will block until the server is no longer
busy (ie until the server calls WaitForConnection). If the server is not
running (ie the pipe does not exist), the client side still blocks. I have
tested this - run the client, observe that it blocks, run the server, the
client unblocks, and the pipe transaction runs to completion.

Ok, I understand it, but I don't like it because my client thread can block
indefinitely. Thus, I can't use my gui thread to do pipe operations because
my gui app will go unresponsive if it blocks connecting to a pipe. So, I
need to go async or launch threads, and now I may have multiple threads
blocked indefinitely and no way to know what is going on.

What I need is a timeout on the Connect, and I need status information
available to the client about the pipe before the connect is attempted. Does
anyone have any bright ideas on this issue?
 
A

Armin Zingler

AMercer said:
What I need is a timeout on the Connect, and I need status information
available to the client about the pipe before the connect is
attempted. Does anyone have any bright ideas on this issue?

The Connect method is overloaded and you can also pass a timeout value.

You might ask in a general Framework group because I think you don't have a
problem with the VB language. (m.p.dotnet.framework.remoting or elsewhere
under framework.* because Pipes are handled under "file I/O" not "Remoting"
in the documentation)


Armin
 
A

AMercer

The Connect method is overloaded and you can also pass a timeout value.

Connect's timeout value has no effect - Connect still blocks indefinitely.
Also, readonly property CanTimeout is false. The documentation of CanTimeout
contains this:

"If you are implementing a stream that must be able to time out, this
property should be overridden to return true."

I'm not implementing a stream, I'm trying to use one. In this context, I
don't know how to override a property. So, I'm still stuck. When I
instantiate an IO.Pipes.NamedPipeClientStream, I have no chance to cause
CanTimeout to be true, and once instantiated, it is readonly.
 
M

Michel Posseth

AMercer said:
Connect's timeout value has no effect - Connect still blocks indefinitely.
Also, readonly property CanTimeout is false. The documentation of
CanTimeout
contains this:

"If you are implementing a stream that must be able to time out, this
property should be overridden to return true."

I'm not implementing a stream, I'm trying to use one. In this context, I
don't know how to override a property. So, I'm still stuck. When I
instantiate an IO.Pipes.NamedPipeClientStream, I have no chance to cause
CanTimeout to be true, and once instantiated, it is readonly.


This works for me

Imports System
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim pipeClient As New NamedPipeClientStream(".", "testpipe2",
PipeDirection.InOut, PipeOptions.None)
pipeClient.Connect(100)
Catch te As TimeoutException
MsgBox(te.Message,MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString,MsgBoxStyle.Critical)
End Try


End Sub
End Class


i get the expected timeout exception


regards

Michel Posseth [MCP]
 
A

AMercer

Ok, I tried the same, and it worked for me as well. It behaves as documented
with one big ugly exception. I was running the client pipe code on a
separate thread, and the TimeoutException is consistently lost when
Connect(timeout) is not contained in a try block. In this case,
Connect(timeout) never returns. Everything works fine if Connect(timeout) is
on the main (gui) thread and/or if Connect(timeout) is in a try block.

IMO, this has nothing to do with pipes or my original post. I think there
are some cases where exceptions are lost when secondary threads are involved,
and I think my situation is one of these cases. I know how to proceed, so
this issue is closed as far as I am concerned.

Michel Posseth said:
AMercer said:
Connect's timeout value has no effect - Connect still blocks indefinitely.
Also, readonly property CanTimeout is false. The documentation of
CanTimeout
contains this:

"If you are implementing a stream that must be able to time out, this
property should be overridden to return true."

I'm not implementing a stream, I'm trying to use one. In this context, I
don't know how to override a property. So, I'm still stuck. When I
instantiate an IO.Pipes.NamedPipeClientStream, I have no chance to cause
CanTimeout to be true, and once instantiated, it is readonly.


This works for me

Imports System
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim pipeClient As New NamedPipeClientStream(".", "testpipe2",
PipeDirection.InOut, PipeOptions.None)
pipeClient.Connect(100)
Catch te As TimeoutException
MsgBox(te.Message,MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString,MsgBoxStyle.Critical)
End Try


End Sub
End Class


i get the expected timeout exception


regards

Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top