Closing named pipe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,in one project I use a named pipe in a mixed managed-unmanaged environment. The server end of the pipe is created within an unmanaged code,while the client end is opened within managed code. In order to open the client end,I had imported the Win32 API functions CreteFile(),SetNamedPipeHandleState(),CloseHandle(). Then I first open the pipe by invoking CreateFile(),then setting the proper state with a call to SetNamedPipeHandleState(),followed by creation of a FileStream object,where i pass the handle to the pipe to the constructor. After I am done,i call the file stream object's Close() method, but it seams that there is some problem,and the pipe is not closed correctly, since at the next attempt to open the pipe, i get an IOException. The server end of the pipe is opened with no restriction to the number of the istances of the pipe that can be created
I even tried to close the pipe by calling the imported CloseHandle(),but the result is the same
Any suggestions what could be the problem are appreciated
Thanks in advance
Svetoslav
 
Svetoslav,

When calling the FileStream constructor, are you passing true or false
for ownership to the handle? You might want to try setting the parameter to
false, and then calling CloseHandle yourself (wrapping the whole thing up in
something that implements IDisposable is a good idea as well).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Svetoslav Vasilev said:
Hi,in one project I use a named pipe in a mixed managed-unmanaged
environment. The server end of the pipe is created within an unmanaged
code,while the client end is opened within managed code. In order to open
the client end,I had imported the Win32 API functions
CreteFile(),SetNamedPipeHandleState(),CloseHandle(). Then I first open the
pipe by invoking CreateFile(),then setting the proper state with a call to
SetNamedPipeHandleState(),followed by creation of a FileStream object,where
i pass the handle to the pipe to the constructor. After I am done,i call the
file stream object's Close() method, but it seams that there is some
problem,and the pipe is not closed correctly, since at the next attempt to
open the pipe, i get an IOException. The server end of the pipe is opened
with no restriction to the number of the istances of the pipe that can be
created.
 
Back
Top