rmcrackan / Dinah.Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In progressBar, last update might be missing

CrustyApplesniffer opened this issue · comments

In your sample:

public static async Task Main(string[] args)
{
	var demo = new Demonstrations();

	demo.ProgressBarUp();
	demo.ProgressBarDown();

	demo.ReadPassword();
}

the last progress value (100 when progress is raising, 1 when progress is decreasing) is not displayed :

Performing some task... [##########] 98% \Done.
Performing some task... [----------]   2% \Done.

(btw you should stop your decreasing progress at 0)

public void ProgressBarDown()
{
	Console.Write("Performing some task... ");

	using var progressBar = new ProgressBar();
        for (int i = 100; i > 0; i--)
	// SHOULD BE for (int i = 100; i >= 0; i--)
	{
		progressBar.Report((double)i / 100);
		Thread.Sleep(20);
	}

	Console.WriteLine("Done.");
}

I recommend to update the display each time the progress value is updated:

In ProgressBarc.cs

public void Report(double value)
{
	// Make sure value is in [0..1] range
	value = Math.Max(0, Math.Min(1, value));
	Interlocked.Exchange(ref currentProgress, value);
	timerHandler(null);
}

Good ideas. Added

Thank you!