Foreach loop directly to progress
void Main()
{
// You can also make custom inline progress bars as follows:
foreach (var element in Enumerable.Range(0, 100).DumpProgressBar("Most common usage of progress"))
{
Thread.Sleep (30);
}
}
public static class Extension
{
public static IEnumerable<T> DumpProgressBar<T>(this IEnumerable<T> valuesList, string title = null)
{
int total = valuesList.Count();
int position = 0;
var progressBar = new Util.ProgressBar(title).Dump();
progressBar.HideWhenCompleted = true;
foreach (var element in valuesList)
{
progressBar.Percent = (++position * 100) / total;
yield return element;
}
}
}
1
vote
karel
shared this idea