Named Pipes - Sample code for new .NET 3.5 classes

B

Bob

I had posted an inquiry under another thread, but I guess it was not
noticed. A couple Q's for anyone familiar with the new
Named Pipes classes:

Is there an easy way to run asynchronously... to block the thread
until data is received? (Most sample code uses "while (true)" polling
loops which would waste CPU cycles)

Also, is there a convention for which program is the 'server' and
which is the 'client'? The limited sample code that I've seen set up
the transmitting program as the client, but I'm not sure what
difference that makes.
 
N

Nicholas Paldino [.NET/C# MVP]

Bob,

There are asynchronous methods on the named pipe classes. They begin
with "Begin" (e.g. "BeginRead", "BeginWrite"), where you will be notified
when they are complete (or you can poll if you wish). The synchronous
methods are simply called Read, Write.

Are you communicating between two .NET programs? If you don't have a
need to support other applications which don't have access to .NET or COM,
then why not use WCF with a named pipe binding? It would be much easier
than having to figure out the messaging pattern on your own, as well as
serialization of types across the channel.
 
A

Arne Vajhøj

Bob said:
Is there an easy way to run asynchronously... to block the thread
until data is received? (Most sample code uses "while (true)" polling
loops which would waste CPU cycles)

If you want to block, then why use async - sync would solve the
problem.

Arne
 

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