本文整理汇总了C#中ProgressBar.Spawn方法的典型用法代码示例。如果您正苦于以下问题:C# ProgressBar.Spawn方法的具体用法?C# ProgressBar.Spawn怎么用?C# ProgressBar.Spawn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgressBar
的用法示例。
在下文中一共展示了ProgressBar.Spawn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public Task Start(CancellationToken token)
{
var random = new Random();
var numberOfSteps = 7;
var overProgressOptions = new ProgressBarOptions
{
BackgroundColor = ConsoleColor.DarkGray,
};
using (var pbar = new ProgressBar(numberOfSteps, "overal progress", overProgressOptions))
{
var stepBarOptions = new ProgressBarOptions
{
ForeGroundColor = ConsoleColor.Cyan,
ForeGroundColorDone = ConsoleColor.DarkGreen,
ProgressCharacter = '─',
BackgroundColor = ConsoleColor.DarkGray,
CollapseWhenFinished = false,
} ;
Parallel.For(0, numberOfSteps, (i) =>
{
var workBarOptions = new ProgressBarOptions
{
ForeGroundColor = ConsoleColor.Yellow,
ProgressCharacter = '─',
BackgroundColor = ConsoleColor.DarkGray,
};
var childSteps = random.Next(1, 5);
using (var childProgress = pbar.Spawn(childSteps, $"step {i} progress", stepBarOptions))
Parallel.For(0, childSteps, (ci) =>
{
var childTicks = random.Next(50, 250);
using (var innerChildProgress = childProgress.Spawn(childTicks, $"step {i}::{ci} progress", workBarOptions))
{
for (var r = 0; r < childTicks; r++)
{
innerChildProgress.Tick();
Program.BusyWait(50);
}
}
childProgress.Tick();
});
pbar.Tick();
});
}
return Task.FromResult(1);
}
示例2: InnerProgressBars
private static void InnerProgressBars(ProgressBar pbar)
{
var innerProgressBars = Enumerable.Range(0, new Random().Next(2, 6))
.Select(s => pbar.Spawn(new Random().Next(2, 5), $"inner bar {s}"))
.ToList();
var maxTicks = innerProgressBars.Max(p => p.MaxTicks);
for (var ii = 0; ii < maxTicks; ii++)
{
foreach (var p in innerProgressBars)
{
InnerInnerProgressBars(p);
p.Tick();
}
Thread.Sleep(4);
}
foreach (var p in innerProgressBars) p.Dispose();
}