コード例 #1
0
        public static int EndReadToEnd(this Stream stream, IAsyncResult ar)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            ByteArrayAsyncResult state = ar as ByteArrayAsyncResult;

            if (state == null)
            {
                throw new InvalidOperationException();
            }

            if (!state.IsCompleted)
            {
                state.AsyncWaitHandle.WaitOne(-1);
            }

            int endReadToEnd = state.Length;

            using (state)
            {
            }

            return(endReadToEnd);
        }
コード例 #2
0
 public static IAsyncResult BeginReadToEnd(this Stream stream, byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
 {
     byte[] tempBuffer = new byte[count];
     ByteArrayAsyncResult result = new ByteArrayAsyncResult(callback, state, buffer, offset, tempBuffer);
     ByteArrayAsyncState asyncState = new ByteArrayAsyncState {Result = result, Stream = stream};
     stream.BeginRead(tempBuffer, 0, count, OnRead, asyncState);
     return result;
 }
コード例 #3
0
        public static IAsyncResult BeginReadToEnd(this Stream stream, byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            byte[] tempBuffer               = new byte[count];
            ByteArrayAsyncResult result     = new ByteArrayAsyncResult(callback, state, buffer, offset, tempBuffer);
            ByteArrayAsyncState  asyncState = new ByteArrayAsyncState {
                Result = result, Stream = stream
            };

            stream.BeginRead(tempBuffer, 0, count, OnRead, asyncState);
            return(result);
        }