Mark Mintoff My superpower is common sense


C# Console Progress Bar

At work, I sometimes find myself needing to make Console applications which take some time. For example, I have a few console applications which parse dump files into objects and then insert the data into a database. Usually, I represent the progress of these applications with a simple incremental percentage display, however I thought I'd create a generic method which would display an ASCII progress bar.

The code itself is pretty self explanatory and probably more verbose than it really needs to be, but it gets the job done and looks good. It is a nice throwback to Pascal and QBasic for me.

EDIT: Amended code to append characters to a string before writing on screen. This fixes the flickering problem.

VN:F [1.9.22_1171]
Rating: 5.0/5 (13 votes cast)
C# Console Progress Bar, 5.0 out of 5 based on 13 ratings
Comments (6) Trackbacks (1)
  1. Hello,

    this 2 lines give me an error!
    for (int i = 0; i < chars; i++) p1 += progressCharacter;
    for (int i = 0; i < barSize – chars; i++) p2 += progressCharacter;



  2. Thank you, this code method is great! I am writing a console application for my company and this will come in very handy indeed.

  3. Absolutely awesome.
    I used Console.WindowWidth and a crazy ascii character (219) to form the bar:
    DrawProgressBar(…, …, Console.WindowWidth, ‘█’);

  4. This worked great, thank you!

  5. This is fantastic!  Thanks so much!

Cancel reply