Indicating progress in console windows

ConsoleProgressBar

Command-line interface tools. We usually prefer to write these when we need a lightweight application to get work done.

Some operations can be lengthy, or we simply want to present the a visual indicator of progress to the user. For this purpose I usually update Console.Title for simplicity’s sake.

However, if the tool is intended for a more wide audience (IT professionals or advanced users) you would want a CLI progress bar.

ConsoleProgress is a static class. Usage is pretty much straight-forward:

  1. Call Reset to reset the progress bar’s state. This is optional if you wish to use the progress bar only once in your program.
  2. Call Update. You can pass a float  to indicate progress using a fraction (0.25 = 25%), or the current and maximum values (e.g. 17 of 100 items processed).
  • If the operation can be canceled, either because of an internal exception or by the user, you can set the Canceled  property to true  to update the console output.

The sample code also contains several test cases, which demonstrate successful and canceled operations. I have also used relevant colors depending on each result.

ConsoleProgressBar


No Responses to “Indicating progress in console windows”  

  1. No Comments

Leave a Reply