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

RenderAndPollDeterminate() public method

Renders the progress bar and automatically updates it on a polling interval. The method blocks until the progress reaches 1 or your poll action throws an OperationCancelledException, whichever comes first. It is expected that you will update the progress via the poll action. You can also update the message during the poll action.
public RenderAndPollDeterminate ( System.Action pollAction, System.TimeSpan pollingInterval ) : void
pollAction System.Action An action to run on each polling interval
pollingInterval System.TimeSpan The polling interval
return void
        public void RenderAndPollDeterminate(Action pollAction, TimeSpan pollingInterval)
        {
            Render();

            try
            {
                while (Progress < 1)
                {
                    Thread.Sleep(pollingInterval);
                    pollAction();
                    Update();
                }
            }
            catch(OperationCanceledException)
            {
                Update();
            }
            finally
            {
                wiper.MoveCursorToLineAfterBottom();
            }
        }