| C# | Visual Basic | Managed C++ |
public virtual AsynchronousBaseStreamException AsynchronousException { get; }
Public Overridable ReadOnly Property AsynchronousException As AsynchronousBaseStreamException
public: virtual property AsynchronousBaseStreamException^ AsynchronousException { AsynchronousBaseStreamException^ get (); }
When the BaseStream throwns an exception during asynchronous I/O the background thread performing the I/O stops and the AsynchronousException property is set. The next time a method is invoked or Position or Mode are set this exception is thrown and AsynchronousException is cleared; the next invocation or set resumes the background thread.
When busy-waiting for bytes to be Available with a BaseStream that may throw exceptions, it's a good idea to use (AsynchronousException!=null) as a stopping condition to avoid the risk of looping forever (once the background thread stops, no more bytes will become available until it resumes).
To clear the AsynchronousException and resume the background thread immediately, use ClearAsynchronousException().