The NetworkStream.BeginRead method may cause the InvalidOperationException exception.


Symptoms


When a single NetworkStream object is used by multiple threads at the same time, calling the BeginRead method may cause the InvalidOperationException exception to be thrown.

Cause


When a call to the NetworkStream.close method or NetworkStream.Dispose method of a NetworkStream object is being made, an attempt to call the NetworkStream.BeginRead method of the same NetworkStream object from another thread may throw the InvalidOperationException.

Resolution


When InvalidOperationException is thrown, destroy the NetworkStream object.

More Information


This is by design behavior.

For more information on the NetworkStream.BeginRead method, refer to the following Microsoft Web site:
http://msdn.microsoft.com/ja-jp/library/system.net.sockets.networkstream.beginread(VS.90).aspx