none
Named Pipes in C#

    Question

  • I need to pass data from one process to another.  In the "Visual C++ Version 6" world I would have used a global named pipe for this task.  I'm developing in C# and would like to know what construct there is for either creating named pipes or for a "new" technique to pass data from one process to the other.

    One other specific is that the process producing the information, i.e., filling the pipe, is a service created using C#.  The service, when it receives a command needs to reply with a small amount of data to the process that sent the command to the service.  I was planning to do this via a pipe.  The service would create the global named pipe while the "client" would access the global named pipe using CreateFile.

    - Neil Shore

     

    Friday, December 23, 2005 5:11 PM

Answers

All replies

  • Hi,

    I am failry new to C# but I have needed to write a multi-threaded messaging service using named pipes. You have to call native windows API functions to implement named pipes in the dot net environment. If you are interested I will send you the code when I have it running correctly.

     

    Alan Seedhouse

    Tuesday, January 03, 2006 10:55 AM
  • Tuesday, January 03, 2006 1:34 PM
  • Alan,

     

    Thanks for your reply.  I have written code for named pipes using Visual C/C++ Version 6.  So, I am familiar with the API and the code required.  I hoped that the .net development environment had a class or namespace, or something that I missed in the documentation, to make the coding easier.

     

    I would be interested in seeing your approach once you have it working.

     

     

     

    Thanks again.

     

    - Neil

     

    Tuesday, January 03, 2006 9:40 PM
  • Andreas,

     

    Thanks for your reply.  I took a quick look at the article, but I'll need some time to review it.  It figures "The Code Project" would have something about it.  It may be overkill for what I need but it looks like a great starting place.  I just thought that I was missing some documentation that would point me to a .net class or namespace to simplify coding pipes.  I guess it is not so.

     

     

     

    Thanks again.

     

    - Neil

     

    Tuesday, January 03, 2006 9:46 PM
  • There is a complete sample provided to send strings to a server and get it returned. I even tested it in C# Express.

    If you can not download the zip from codeproject you can get it at the authors website.

    I am also looking to do some communication between .NET applications and it seems to be few alternatives to remoting. This could be an interesting alternative.

     

    Tuesday, January 03, 2006 10:07 PM
  • Andreas,

    Thanks, I've downloaded the project and played with it.  I will probably use it in a stripped down version.

    - Neil

     

    Sunday, January 08, 2006 7:25 PM
  • The example that is provided cannot be used with a multi-threaded client because the Read blocks the Write call too (on the client-side)

    This is a simple implementation here ..

    http://i-d-e-a-s.blogspot.com/2006/04/net-and-named-pipes.html

    basically you use CreatFile to create a client pipe and pass the handle to the System.IO.FileStream and then you can use BeginRead and BeginWrite for Async IO.

     

    --Yatharth

     

    Sunday, April 23, 2006 7:04 AM
  • With the advent of newer technology, if you have been waiting all this time <g> ...I have created a named pipe system using WCF and .Net 3. Here is my article on my blog entitled Create a Intra-Application Named Pipe using WCF in .Net .
    Saturday, September 22, 2007 2:05 AM
  • OmegaMan,

     

    No, LOL, I haven't been waiting all this time.  My solution was to write a DLL in C++, which uses the Windows API, and then use a wrapper for the DLL in the C# application.  It's running and installed in a number of locations.

     

    However, thanks for the WCF .Net 3 solution.  It will be a while before I can work in the WCF and .Net 3 world.  I will still take a look at your blog and download the code.

     

    Thanks for the post.

     

    ShoreNuff

    Wednesday, October 03, 2007 1:46 AM
  • Hi,
    Can I use this on a pre-compiled application? What I ask to do is send value from one exe application to another. Unfortunately, our company has no proper documentaion of these 2 old applications. One application has a listview control that has columns and rows, what i need to get is the value of the 2nd column of that list view when each row is clicked and pass it to a textbox to the other exe application. I heard about sub hooking but I'm not really sure is this is the way forward. I'm currently using C# to make this bridge. Can anyone help me please? I've looked at Omegaman's article about NamedPipe but not sure if I can use this even if I don't have access to the sourcecode. As I have stated it's a pre-compiled exe. Please help. Many Thanks.
    Tuesday, July 28, 2009 9:02 AM
  • No my solution won't work for your situation...but.... Is the target application managed .Net? If so you can decompile the applications and rebuild them anew. Look into the .Net Reflector to see if it can provide the source for you. Chances are you can decompile the code as long as the code wasn't obfusicated by design.

    Once the code is in your hands, you can then use my process for IPC. HTH
    William Wegerson (www.OmegaCoder.Com)
    Tuesday, July 28, 2009 12:19 PM
  • Thanks Omegaman. My question now is, can subhooking be able to solve this issue? And also may I ask do I need a software to decompile it? Thanks.
    Tuesday, July 28, 2009 12:32 PM
  • I cannot answer about subhooking. I suggest you post a new forum topic. GL
    William Wegerson (www.OmegaCoder.Com)
    Tuesday, July 28, 2009 2:46 PM