simida <(E-Mail Removed)> wrote:
> Yes, But if you want to copy a big file.you should do use buffer to
> copy file and retrieve information about copied file size to notify UI
> progress bar.
A few comments about your code:
1) Why bother using the file's length to start with? Just keep reading
until Stream.Read returns 0. That can make the code simple:
int bytesRead;
while ( (bytesRead = fRStream.Read(bytes, 0, bytes.Length)) != 0)
{
...
}
There's no need to break inside the loop then.
2)
if (n == bytes.Length)
{
// Write data the destination file.
fWStream.Write(bytes, 0, bytes.Length);
}
else
{
fWStream.Write(bytes, 0, n);
}
This is equivalent to:
fWStream.Write (bytes, 0, n);
3) There's no need to explicitly flush and close a stream if you've got
it within a using statement.
4) This should be performed on a non-UI thread - which means that the
OnCopying event will need to marshall over to the UI thread to report
progress, using Control.Invoke or Control.BeginInvoke.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too