PowerArgs.Cli.CliProgressBar.RenderAndPollIndeterminate C# (CSharp) Method

RenderAndPollIndeterminate() public method

Renders the progress bar and shows an indeterminate progress animation until the operation completes
public RenderAndPollIndeterminate ( Func heartbeat, System.TimeSpan pollingInterval ) : void
heartbeat Func a function that should return true as long as you want to continue to block. If you return false then this method will return.
pollingInterval System.TimeSpan How fast you want the progress bar to call your heartbeat function
return void
        public void RenderAndPollIndeterminate(Func<bool> heartbeat, TimeSpan pollingInterval)
        {
            Render();
            indeterminateHighlightIndex = 0;
            bool cancelled = false;
            try
            {
                var bgTask = Task.Factory.StartNew(() =>
                {
                    while (cancelled == false)
                    {
                        Update();
                        indeterminateHighlightIndex++;
                        if (indeterminateHighlightIndex > Width - 4)
                        {
                            indeterminateHighlightIndex = 0;
                        }
                        Thread.Sleep(50);
                    }
                });

                while (heartbeat())
                {
                    Thread.Sleep(pollingInterval);
                }
            }
            finally
            {
                indeterminateHighlightIndex = -1;
                Update();
                cancelled = true;
            }
        }