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 weeks 3 days ago
10 weeks 1 day ago
12 weeks 1 day ago
22 weeks 12 hours ago
44 weeks 1 day ago
44 weeks 1 day ago
47 weeks 2 days ago
47 weeks 2 days ago
47 weeks 2 days ago
49 weeks 1 day ago