Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program hang when using Named Pipe

Status
Not open for further replies.

xjazz

Programmer
Jan 11, 2005
21
US
hi, i am using named pipe to pass values from a dll to a exe file.
the executable is an application run as the named pipe server. and it will do something else besides get values from the dll which is the client side of the named pipe.
i used a Do Loop in the server. but the program will hang until it read something from the pipe.
i tried DoEvents too, but as long as it hits the ReadFile function, it will hang,until something coming in.

anyone has good idea to solve this?
so that my application can do something else while it's listening the pipe.

thanks
 
Did you try calling PeekNamedPipe to make sure there is some data to read before calling ReadFile?

Maybe this way you can avoid calling ReadFile unless you will have something to read.
 
tried,
but failed.
because i found actually, it's the ConnectNamedPipe function block the process.

it will hang until it connected to that named pipe.

don't know what to do now. :(
 
i tried.
i use this to create named pipe:
dwOpenMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_OVERLAPPED
dwPipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE
hPipe = CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode, _
10, 10000, 2000, 10000, sa)


then use :
res = ConnectNamedPipe(hPipe, ByVal 0)
to connect to it.

but still the same. will block until connected.


 
FILE_FLAG_OVERLAPPED is insufficient by itself to achieve overlapped mode. You need to pass a correctly filled OVERLAPPED structure as the second parameter of ConnectNamedPipe...it can get pretty tricky, and I don;t have time to put an example together right now. Here, this is what Microsoft have to say:
 
strongm -

Overlapped I/O for a VB newbie? Are you sure that's wise?

Chip H.
;-)


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
strongm:
you are right.
thank you so much
finally, it works.

thank you everybody
:)
 
Sheco -
Someone using named pipes would be expected to understand the difference between synchronous and asynchronous I/O.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top