nntpnews.net

Global Usenet Archiver


Register

Named Pipes - Sample code for new .NET 3.5 classes

Reply

  #1  
Old 25-11-08, 07:51 PM
Bob
 
Posts: n/a
Default Named Pipes - Sample code for new .NET 3.5 classes

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.

Reply With Quote
  #2  
Old 25-11-08, 08:03 PM
Nicholas Paldino [.NET/C# MVP]
 
Posts: n/a
Default Re: Named Pipes - Sample code for new .NET 3.5 classes

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.


--
- Nicholas Paldino [.NET/C# MVP]
-
Code:
Content visible to registered users only.
"Bob" <Bob@nospam.com> wrote in message
news:ukloi459bq3fv59mkldl228qqc0thri0jj@4ax.com...
>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.
>



Reply With Quote
  #3  
Old 26-11-08, 02:53 AM
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
 
Posts: n/a
Default Re: Named Pipes - Sample code for new .NET 3.5 classes

Bob wrote:
> 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
Reply With Quote
  #4  
Old 26-11-08, 10:03 AM
Bob
 
Posts: n/a
Default Re: Named Pipes - Sample code for new .NET 3.5 classes

On Tue, 25 Nov 2008 15:03:35 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mvp@spam.guard.caspershouse.com> wrote:

>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.


I was trying to avoid polling, mostly to keep from wasting cycles.
It's been quite a while since I've looked at Named Pipes, and of
course that was in unmanaged C++. I'll keep looking for sample code
for the .NET calls. Should be somewhere now that Named Pipes are
officially supported.

> 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.


Yes, I'll eventually be checking into WCF. For now, one app is .NET,
the other is Win32 unmanaged. Not sure if WCF could still be used in
any form on the .NET side.

Reply With Quote
  #5  
Old 03-12-08, 07:03 AM
Bob
 
Posts: n/a
Default Re: Named Pipes (revisited) - Sample code for new .NET 3.5 classes

On Tue, 25 Nov 2008 21:53:18 -0500, Arne Vajhøj <arne@vajhoej.dk>
wrote:

>Bob wrote:
>> 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


Got sidetracked with a couple other things, but just got back to this.
While the straight asynch WaitForConnection()/Read() functions would
block, as I wanted, there does not seem to be any graceful mechanism
for interacting after the asynch calls are made. They would be a
temporary dead end until the next state change.

So if the thread needs to be closed (app shutdown or whatever), it
seems inelegant to just end the thread. And recovery from errors
(client disconnects, for example) does not seem easy.

The goal is simply to have the server wait for client apps to connect,
but I'd like to continually monitor status, and afford the opportunity
to recover from errors, etc. Seems like there should be available
samples that show how to code the framework, but I haven't found
anything yet.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
persistent named pipes? kj comp.unix.shell 2 02-03-09 10:33 PM
Named Pipes and ERROR_PIPE_BUSY Paul Baker [MVP, Windows Desktop Experience] microsoft.public.win32.programmer.kernel 4 17-02-09 07:53 PM
SQL Server Over Named Pipes David Gray microsoft.public.sqlserver.server 2 02-01-09 05:01 AM
Named Pipes problem rangerjim comp.os.ms-windows.programmer.win32 1 16-10-08 05:40 PM
Require a sample code in VB.NET for Calling/Storing datafrom/to SQL2K5 Server mandar udawant microsoft.public.dotnet.languages.csharp 2 14-08-08 08:49 AM


All times are GMT +1. The time now is 09:00 AM. Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0



For ads on this site use independent advertising companies. These companies may use some data (which does not include your name, address, email address or telephone number) about your visits to this and other websites to create advertisements on products and services you might enjoy. If you'd like more information and to know the options available to prevent the use of such information by these companies, click here

Abuse Ticket System