-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathFixedDurationExample.cs
42 lines (37 loc) · 1.01 KB
/
FixedDurationExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ShellProgressBar.Example.Examples
{
public class FixedDurationExample : ExampleBase
{
protected override Task StartAsync()
{
var options = new ProgressBarOptions
{
ForegroundColor = ConsoleColor.Yellow,
ForegroundColorDone = ConsoleColor.DarkGreen,
BackgroundColor = ConsoleColor.DarkGray,
BackgroundCharacter = '\u2593'
};
var wait = TimeSpan.FromSeconds(5);
using (var pbar = new FixedDurationBar(wait, "", options))
{
var t = new Thread(()=> LongRunningTask(pbar));
t.Start();
if (!pbar.CompletedHandle.WaitOne(wait))
Console.Error.WriteLine($"{nameof(FixedDurationBar)} did not signal {nameof(FixedDurationBar.CompletedHandle)} after {wait}");
}
return Task.CompletedTask;
}
private static void LongRunningTask(FixedDurationBar bar)
{
for (var i = 0; i < 1_000_000; i++)
{
bar.Message = $"{i} events";
if (bar.IsCompleted) break;
Thread.Sleep(1);
}
}
}
}