Code List: ----------------------------------------------- -------------------------- / *********************** ***************************************** File Name: frmmain.cs ** Copyright (c) 1999 -2003 ** Creator: Firephoenix ** Created Date: 2004-11-13 15: 24 ** modifier: ** modify date: ** description: ** Version: 1.0 ***** *********************************************************** *********** /
#region Using Directivesusing System; using System.IO; using System.Xml; using System.Collections; using System.Reflection; using System.Text; using System.Data; using System.ComponentModel; using System.Windows.Forms; using System .Drawing; system.threading; #ENDREGION
namespace WindowsApplication4 {///
Public frmmain () {// // Windows Form Designer Support for // InitializationComponent ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#Region Initialize Components ///
///
#ndregion
INT TOTALSIZE; / / TOTAL SIZE INT POSITION; / / POSITION const Int buffer_size = 4096; byte [] buffer; stream stream;
Private void btncopy_click (object sender, system.eventargs e) {string strfile = "
OpenFiledialog DLG = New OpenFiledialog (); if (DLG.ShowDialog () == DialogResult.ok) {strfile = DLG.FileName;} else {return;
FileStream Fs = New FileStream (Strfile, FileMode.open, FileAccess.read); Totalsize = (int) fs.length; stream = fs; // delete file heich aready exists. If (file.exists ("c: // copyedfile .bin ")) File.delete (" c: //copyedfile.bin "); // copy file while larger Than 4kb. if (Totalsize> Buffer_size) {buffer = new byte [buffer_size];
// async invoke stream.beginread (buffer, 0, buffer_size, new asynccallback (asyncopyfile), null;} else {fs.close ();}} ///
// Write to Disk filestream fswriter = new filestream ("c: //copyedfile.bin", filemode.Append, fileaccess.write; fswriter.write (buffer, 0, buffer.length); fswriter.close (); / / Current stream position position = readedLength; // Response UI MethodInvoker m = new MethodInvoker (SynchProgressBar); m.BeginInvoke (null, null); if (position> = totalSize) // Read over {stream.Close ().; // Close FileStream Return;}
// Continue to read and write lock (stream) {INT leftsize = Totalsize - Position;
IF (Leftsize Stream.Beginread (Buffer, 0, Buffer.Length, New AsyncCallback (asynccopy), null;}} Private void synchprogressbar () {this.progressbar1.maximum = Totalsize; this.progressbar1.value = position;}}}