Exemple #1
0
        async Task <int> ReadNextChunkAsync(LoadFileAsyncState state)
        {
            int bytesRead = await Task.Factory.FromAsync <byte[], int, int, int> (
                state.ResponseStream.BeginRead,
                state.ResponseStream.EndRead,
                state.Buffer, 0, state.BufferLength, null
                ).ConfigureAwait(false);

            if (bytesRead > 0)
            {
                state.BytesLoaded += bytesRead;

                if (state.OnProgress != null)
                {
                    state.OnProgress(((float)state.BytesLoaded) / state.TotalBytes);
                }

                state.OutputStream.Write(state.Buffer, 0, bytesRead);
            }

            return(bytesRead);
        }
        async Task<int> ReadNextChunkAsync (LoadFileAsyncState state)
        {
            int bytesRead = await Task.Factory.FromAsync<byte[], int, int, int> (
                state.ResponseStream.BeginRead,
                state.ResponseStream.EndRead,
                state.Buffer, 0, state.BufferLength, null
            ).ConfigureAwait (false);

            if (bytesRead > 0) {
                state.BytesLoaded += bytesRead;

                if (state.OnProgress != null)
                    state.OnProgress (((float) state.BytesLoaded) / state.TotalBytes);

                state.OutputStream.Write (state.Buffer, 0, bytesRead);
            }

            return bytesRead;
        }