Here's a (I think) simple question:

If I issue multiple async writes on a NetworkStream, is the data guaranteed to be sent in the correct order?

i.e.

stream.BeginWrite(.. data A ...);
stream.BeginWrite(.. data B ...);

Will data A always be completely sent before B is sent?

I figure/guess no, but it would be useful if BeginWrite could be used like this...

Thanks for listening

Re: Multiple concurrent asynchronous writes on a Stream (NetworkStream by David

David
Thu Jul 22 05:25:32 CDT 2004

There is no way that it could be assured that it would ALWAYS be in the
correct order. Remember that BeginWrite spawns a new thread, and which
thread starts in what order (particularly in this case as it is part of
the ThreadPool - so you might end up with it actually being queued...)
is determined be the Operating System.

HTH

David

"Rua Haszard Morris" <RuaHaszardMorris@discussions.microsoft.com> wrote
in message news:DAA3C13E-6A9A-4E3C-BE2C-D76DDC2EDEF7@microsoft.com:
> Here's a (I think) simple question:
>
> If I issue multiple async writes on a NetworkStream, is the data
> guaranteed to be sent in the correct order?
>
> i.e.
>
> stream.BeginWrite(.. data A ...);
> stream.BeginWrite(.. data B ...);
>
> Will data A always be completely sent before B is sent?
>
> I figure/guess no, but it would be useful if BeginWrite could be used like
> this...
>
> Thanks for listening


Re: Multiple concurrent asynchronous writes on a Stream (NetworkSt by RuaHaszardMorris

RuaHaszardMorris
Thu Jul 22 17:21:02 CDT 2004

cheers for that.

As I suspected - it is up to the programmer to take responsibility for ensuring correct sequence of data..

So I should package data A & B into one buffer and write that, and ensure it's completed before issuing another Write or BeginWrite (which is what my code does at present anyway...)

cheers,
"David Williams , VB.NET MVP" wrote:

> There is no way that it could be assured that it would ALWAYS be in the
> correct order. Remember that BeginWrite spawns a new thread, and which
> thread starts in what order (particularly in this case as it is part of
> the ThreadPool - so you might end up with it actually being queued...)
> is determined be the Operating System.
>
> HTH
>
> David
>
> "Rua Haszard Morris" <RuaHaszardMorris@discussions.microsoft.com> wrote
> in message news:DAA3C13E-6A9A-4E3C-BE2C-D76DDC2EDEF7@microsoft.com:
> > Here's a (I think) simple question:
> >
> > If I issue multiple async writes on a NetworkStream, is the data
> > guaranteed to be sent in the correct order?
> >
> > i.e.
> >
> > stream.BeginWrite(.. data A ...);
> > stream.BeginWrite(.. data B ...);
> >
> > Will data A always be completely sent before B is sent?
> >
> > I figure/guess no, but it would be useful if BeginWrite could be used like
> > this...
> >
> > Thanks for listening
>
>