public static void EndCopy(IAsyncResult ar)
        {
            StreamCopyState result = (StreamCopyState)ar;

            if (result.Error != null)
            {
                throw result.Error;
            }
        }
        public static IAsyncResult BeginCopy(Stream from, Stream to, AsyncCallback callback, object state)
        {
            byte[] buffer = new byte[32768];

            StreamCopyState asyncState = new StreamCopyState(from, to, buffer, callback, state);

            from.BeginRead(buffer, 0, buffer.Length, asyncState.DataRead, null);

            return(asyncState);
        }