Exemple #1
0
        private static void readCallback(IAsyncResult ar)
        {
            CopyState state = ar.AsyncState as CopyState;
            var       rlen  = state.From.EndRead(ar);

            state.ReadSize += rlen;
            state.To.Write(state.Buffer, 0, rlen);
            state.WriteSize += rlen;
        }
Exemple #2
0
        public static void StreamCopy(Stream from, Stream to)
        {
            CopyState cstate = new CopyState(from, to);

            do
            {
                var aresult = from.BeginRead(cstate.Buffer, 0, CopyState.BUFFER_SIZE, readCallback, cstate);
                aresult.AsyncWaitHandle.WaitOne();
            } while (cstate.ReadSize != cstate.FileLength && cstate.WriteSize != cstate.FileLength);
            to.Flush();
        }
Exemple #3
0
        private static void writeCallback(IAsyncResult ar)
        {
            CopyState state = ar.AsyncState as CopyState;

            state.To.EndWrite(ar);
        }