I am currently creating a file copying facility that works on console. There are 3 basic classes that exist within this, the first one is the program itself which takes a source and destination and is as follows:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Source:");
string path = Console.ReadLine();
Console.WriteLine("target:");
string target = Console.ReadLine();
Copy newCopy = new Copy();
newCopy.CopyFunction(path, target);
Console.ReadLine();
}
}
The second class is the Copy.CS which is as follows:
class Copy
{
public void CopyFunction(string source, string destination)
{
string sourceFile = source;
string destinationFile = destination;
File.Copy(sourceFile, destinationFile);
Console.Write("Files are being copied... ");
using (var progress = new ProgressBar())
{
for (int i = 0; i <= 100; i++)
{
progress.Report((double)i / 100);
Thread.Sleep(20);
}
}
Console.WriteLine("File Copied");
}
}
For the final class, I implemented the ProgressBar.cs class provided by @DanielWolf
https://gist.github.com/DanielSWolf/0ab6a96899cc5377bf54
The problem I'm currently facing is that the file copying function works, and so does the progress bar, but they work separately. For example, the console will spend a while on a blank screen while it processes what's happening, and then after it's completed, a quick animation of the progress bar is displayed.
I was wondering if I could synchronise the progress bar with the copying process so that it moves at a similar rate while it's happening?