Link Search Menu Expand Document

Progress Bar

Simulate a progress bar for a hypothetical task consisting of 20 steps. Take the following code as a starting point:

Console.CursorVisible = false;
Console.WriteLine("Task in progress...");
Console.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
Thread.Sleep(200);
Console.Write(" ");

and make the program output look like this:

screenshot

Hint 1: Each step can be represented by a space (" ") character printed in the console with a white background. So you need to print 20 spaces. The line Console.BackgroundColor = ConsoleColor.White; changes the background to white. Notice that it doesn't affect the text printed prior to that statement.

Hint 2: Notice the Thread.Sleep(200); line above. This is needed to slow down the animation. The 200 represents the number of miliseconds to wait until proceeding to the next statement. You can experiment with that number (or remove the line completly) to see how it affects the output.