When continuously adding new progress bars and it is run in the new windows terminal and it starts scrolling, the progress bars do not behave properly. I'm not sure how to describe what happens, but here's a minimal example:
static SemaphoreSlim semaphore = new SemaphoreSlim(2);
static void Main(string[] args)
{
var random = new Random();
var tasks = new List<Task>();
var bars = new List<ProgressBar>();
Console.WriteLine(".\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n");
for (int i = 0; i < 10; i++)
{
tasks.Add(Task.Run(() => ManageTasks(random, bars)));
}
Task.WaitAll(tasks.ToArray());
}
static async Task ManageTasks(Random random, List<ProgressBar> bars)
{
while (true)
{
await semaphore.WaitAsync();
Task.Run(async () =>
{
var fileCount = random.Next(1, 50);
var bar = new ProgressBar(fileCount);
lock (bars) bars.Add(bar);
bar.Refresh(0, $"New Task {bars.Count}");
for (int j = 0; j < fileCount; j++)
{
bar.Next($"File {j + 1}");
await Task.Delay(random.Next(10, 100));
}
semaphore.Release();
});
}
}
It works fine in the default cmd on windows.
When continuously adding new progress bars and it is run in the new windows terminal and it starts scrolling, the progress bars do not behave properly. I'm not sure how to describe what happens, but here's a minimal example:
It works fine in the default cmd on windows.