While working on TVRenamer I came across the need to give progress feedback for the user and give the user the ability to stop copying and since System.IO.File.Copy or Move doesn't provide any feedback and using the VB.NET copy methods means that this will involve another DLL and might not work on mono supported systems, beside that it doesn't give you control over the UI, so I went on and created my own class.
The idea is to have two streams one to read the source file and the other to write to the destination, while raising an event when progress is made, the class exposed one property which is the buffer size, buffer size will impact performance I found the 3MB is a good buffer size in general.
Here's an example of how to use the class:
oFS.CopyProgress += new EventHandler<FileSystem.CopyProgressEventArgs>(oFS_CopyProgress);
bool success = oFS.CopyFile(sourceFileName, destFileName);
if (success)
{
lblProgressStatus.Text = "File copied successfully";
}
void fs_CopyProgress(object sender, FileSystem.CopyProgressEventArgs e)
{
pb.Value = (int)(e.percentage * 100);
Application.DoEvents();
}
Recent comments
1 hour 49 min ago
1 hour 51 min ago
7 hours 31 min ago
7 hours 33 min ago
8 hours 6 min ago
9 hours 9 min ago
9 hours 28 min ago
9 hours 30 min ago
9 hours 31 min ago
9 hours 46 min ago