Is NetworkStream.BeginWrite thread-safe?

  • Thread starter Thread starter Robert Crago
  • Start date Start date
R

Robert Crago

Hi there,

[I can't find a dotnet.framework.networking group to post
to so I'm posting here. If there is a better place,
please let me know...]

Can an asynchronous NetworkStream.BeginWrite/EndWrite
combination using one thread be interrupted by another
thread writing to the same stream, causing the two
streams of data to become mingled?

Or is a single NetworkStream write call guaranteed to
completely send all its bytes before another thread
sending to the same stream can commence?

I would appreciate your help with this...

Robert
 
Robert Crago said:
Can an asynchronous NetworkStream.BeginWrite/EndWrite
combination using one thread be interrupted by another
thread writing to the same stream, causing the two
streams of data to become mingled?

As the documentation says, instance methods [such as BeginWrite/EndWrite]
are not guaranteed to be thread safe.

Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
 
If you hit F1 while your cursor is resting on the name of the class, you'll
see the documentation for that class. It has a section for ThreadSafety.
 
I don't believe so, since BeginWrite is an instance method,

Also, I'm not sure it would be good form to share the NetworkStream
reference without some sort of Controller to syncronize the access via
Monitor or lock and hence give you thread safety...
 
Back
Top