Async namedpipe application

  • Thread starter Thread starter PFx
  • Start date Start date
P

PFx

Hi, i am having a difficult time with developing an application using
asynchronous named pipes. I use a NamedPipeServerStream but for some reason
my beginwaitforconnection-callback-method gets executed at 'strange' times;
like when closing the server. The server-application is a Windows-forms app

Do I have to disconnect in the callback-method?
Am I missing something else?


The namedpipeserverstream is set up in method main()

internal void main()
{

this._pipe = new NamedPipeServerStream("abc"
, PipeDirection.In
, 1
, PipeTransmissionMode.Byte
, PipeOptions.Asynchronous
);

setUpPipe();

Application.Run(new Form1());
}

My callback-code looks like this:

private void setUpPipe()
{

this._pipe.BeginWaitForConnection(
iar => {

this._pipe.EndWaitForConnection(iar);

System.Diagnostics.Debug.WriteLine("...");

this._pipe.Disconnect();

setUpPipe();

}
, null
);
}


Kind regards
 
Thanks for your advice.
It 's exactly what I ended with.

But I am still confused with the 'maxNumberOfServerInstances'-parameter
in the constructor. If > 1, how does it map to threads? I still have to
create some more background-threads and an equal number of pipe-instances for
my multithreaded-listener-application (?).
Documentation and community-info about this topic is quite sparse ...

private void setUpPipe()
{
this._pipe.BeginWaitForConnection(
iar => {
try
{
this._pipe.EndWaitForConnection(iar);

if (!this._pipe.IsConnected) { return; }


Trace.WriteLine("Do something");

this._pipe.Disconnect();

// Continue listening.
setUpPipe();
}
catch (ObjectDisposedException) {} // Application shutdown.
catch (Exception exx)
{
Trace.WriteLine("2: " + exx.ToString());
}
}
, null
);
}


Thanks and regards

Philippe
 
Back
Top