public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            ChainedAsyncResult <int> result = new ChainedAsyncResult <int>(callback, state);

            if (this.completeSynchronously)
            {
                result.UpdateCompletedSynchronously(this.completeSynchronously);
                result.Result = this.Read(buffer, offset, count);
                result.OnComplete();
            }
            else
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    result.UpdateCompletedSynchronously(this.completeSynchronously);
                    result.Result = this.Read(buffer, offset, count);
                    result.OnComplete();
                },
                                             null);
            }

            return(result);
        }
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            ChainedAsyncResult <NullType> result = new ChainedAsyncResult <NullType>(callback, state);

            if (this.completeSynchronously)
            {
                result.UpdateCompletedSynchronously(this.completeSynchronously);
                try
                {
                    this.Write(buffer, offset, count);
                    result.OnComplete();
                }
                catch (Exception e)
                {
                    result.OnComplete(e);
                }
            }
            else
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    result.UpdateCompletedSynchronously(this.completeSynchronously);
                    try
                    {
                        this.Write(buffer, offset, count);
                        result.OnComplete();
                    }
                    catch (Exception e)
                    {
                        result.OnComplete(e);
                    }
                },
                                             null);
            }

            return(result);
        }