Skip to content

Please support the latest (new) Windows Terminal #3

Description

@fiso64

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions