BeginWrite (byte [] buffer, int offset, int count, AsyncCallback callback, object state)
{
if (!CanWrite)
throw new NotSupportedException ("This stream does not support writing");
// Creating a class derived from Stream that doesn't override BeginWrite
// shows that it actually calls Write and does everything synchronously except
// when invoking the callback, which is done from the ThreadPool.
// Just put this in the Write override:
// Console.WriteLine ("Write");
// Console.WriteLine (Environment.StackTrace);
// Thread.Sleep (10000);
StreamAsyncResult result = new StreamAsyncResult (state);
try {
Write (buffer, offset, count);
result.SetComplete (null);
} catch (Exception e) {
result.SetComplete (e);
}
if (callback != null)
callback.BeginInvoke (result, null, null);
return result;
}