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
8 hours 49 min ago
8 hours 51 min ago
14 hours 30 min ago
14 hours 32 min ago
15 hours 5 min ago
16 hours 9 min ago
16 hours 27 min ago
16 hours 29 min ago
16 hours 30 min ago
16 hours 45 min ago