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; }
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(); }
private static void writeCallback(IAsyncResult ar) { CopyState state = ar.AsyncState as CopyState; state.To.EndWrite(ar); }