In my career I’ve made a lot of console applications. Purposes of that application was varied but some of them have one common thing: steps/stages. I’ve found out nice library which helps you display steps progress. The name of that library is … ShellProgressBar. Repository of ShellProgessBar is on github. You can use that library with .NET Core. There is a really good documentation on github. So, I’ll show you very simple example of fake import application with ShellProgressBar.
You can add ShellProgressBar to project by this command:
[raw]
dotnet add package ShellProgressBar –version 4.1.1
[/raw]
This is example of fake import application:
[csharp]
using System;
using System.Threading;
using ShellProgressBar;
namespace ShellProgressBarExample {
class Program {
static void Main (string[] args) {
try {
Test ();
} catch (Exception ex) {
Console.WriteLine (ex);
}
Console.ReadKey ();
}
static void Test () {
var totalTicks = 5;
var options = new ProgressBarOptions {
ProgressCharacter = ‘─’,
ProgressBarOnBottom = true
};
using (var pbar = new ProgressBar (totalTicks, “Start importing”, options)) {
Thread.Sleep (2000);
pbar.Tick (“Step 1 of 5: reading configuration”);
Thread.Sleep (2500);
pbar.Tick (“Step 2 of 5: downloading files from ftp”);
Thread.Sleep (2500);
pbar.Tick (“Step 3 of 5: processing files”);
Thread.Sleep (2500);
pbar.Tick (“Step 4 of 5: saving data in database”);
Thread.Sleep (2500);
pbar.Tick (“Step 5 of 5: deleting imported files”);
}
}
}
}
[/csharp]
The result: