Mpdreamz / shellprogressbar

ShellProgressBar - display progress in your console application
MIT License
1.43k stars 134 forks source link

Child progress not displayed #36

Open J4C0814N opened 5 years ago

J4C0814N commented 5 years ago

I have some code essentially the same as below:

ProgressBarOptions options = new ProgressBarOptions
{
    ForegroundColor = ConsoleColor.Yellow,
    BackgroundColor = ConsoleColor.DarkYellow,
    ProgressCharacter = '─'
};
ProgressBarOptions childOptions = new ProgressBarOptions
{
    ForegroundColor =ConsoleColor.Green,
    BackgroundColor = ConsoleColor.DarkGreen,
    ProgressCharacter = '─',
    CollapseWhenFinished = false
};

int numChildren = 2;

using (var pbar = new ProgressBar(numChildren, "Total Progress", options))
{
    // Some prep code
    List<myObject> ReturnedResults1 = GetResults();
    using (var child = pbar.Spawn(ReturnedResults1.Count, "Child task 1", childOptions))
    {
        foreach(var result in ReturnedResults1)
        {
            // process result
            child.Tick();
        }
    }

    pbar.Tick();

    // Some more prep code
    List<myObject> ReturnedResults2 = GetResults2();

    using (var child = pbar.Spawn(ReturnedResults2.Count, "Child task 2", childOptions))
    {
        foreach(var result in ReturnedResults2)
        {
            // process result2
            child.Tick();
        }
    }
    pbar.Tick();
}
Console.WriteLine("Done.");

The "Total progress" displays and increments correctly as the code runs, but the two child progress bars are not displayed at all.

Once all the code is complete (it does all run to completion) there are about 6 blank lines after the total progress bar before the "Done" text.

ransagy commented 5 years ago

I get the same issue when running from windows 10's cmd but oddly enough it seems to work when running from Visual Studio.

It also works for me when run from PowerShell.

EDIT 1: I tested this some more; This seems to be related to the fact child progress bars aren't not drawn if considered "off screen". I think the case here is that for some reason they are considered off screen, maybe because it doesn't scroll to accommodate them.

EDIT 2: The above does seem to be right. If it is, I suggest that the check for whether or not to draw off-screen be evaluated on every child progress' tick, and not once as it seems to be now.

cc @Mpdreamz

J4C0814N commented 5 years ago

Thanks for the testing and insight. Not sure what you mean by "When running from Visual Studio" but for me on Windows 10 it does not seem to work anywhere, from the compiled binary in cmd, or debugging in VS. I have tried using release configs and "Start without debugging" from VS directly and they still don't seem to display.

Running the compiled exe from PowerShell does display them though as you mentioned.

ransagy commented 5 years ago

By "Running from visual studio" i meant just running in debug, as you said. I've been using VS2019 Preview lately, which opens its own kind of cmd window, which might be why its working for me.

For me, as long as there is enough space to display the child progress bars when SPAWNING them, they will appear as intended. Otherwise, They won't at all during ticks and will just emit blank lines at the end as you noted.

J4C0814N commented 5 years ago

Interesting, that's good to know. I should have mentioned I am using VS2017, for me using the default console app window size and the exact sample child process sample app with no other console output, the child bars still do not show. Its not core to my app so I have been able to just use top level progress bars. Sounds like it fixes itself in VS2019

L3tum commented 4 years ago

Interestingly for me no child is ever spawned neither in VS2019, CMD or Powershell even if I manually scroll past to give more "space" to the progress bars. Just empty lines

ransagy commented 4 years ago

Yeah, In newer updates of powershell/VS this no longer works for me at all.

gfs commented 3 years ago

This issue still exists on Windows 10.