Mpdreamz / shellprogressbar

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

Crashes immediately in VS code #35

Closed eiredrake closed 4 years ago

eiredrake commented 5 years ago

Pretty sure this is caused by the differing environment that VS code offers but the following code works in visual studio as a core 2.2 console app just fine. But opening it up in VS Code it crashes immediately on the using ProgressBar line.

           const int totalTicks = 10;
            var options = new ProgressBarOptions
            {
                ForegroundColor = ConsoleColor.Yellow,
                BackgroundColor = ConsoleColor.DarkYellow,
                ProgressCharacter = '─'
            };

            using (var pbar = new ProgressBar(totalTicks, "main progressbar", options))
            {
                for(var index = 0; index < 100; index++)
                {
                    pbar.Tick(index, "Test");
                    System.Threading.Thread.Sleep(500);
                }
            }

The exception message is:

Exception has occurred: CLR/System.IO.IOException An unhandled exception of type 'System.IO.IOException' occurred in System.Console.dll: 'The handle is invalid' at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded) at System.Console.get_CursorTop() at ShellProgressBar.ProgressBar..ctor(Int32 maxTicks, String message, ProgressBarOptions options) at DataTableTest.Program.Main(String[] args) in C:\Users\ekramer\Documents\VS Code Projects\DataTableTest\Program.cs:line 24

At this point theirs probably nothing that can be done until VS code matures a bit more but I figured I'd let you guys know so that people using VS code won't be surprised when this happens. Like I said it works just fine in Visual Studio.

dlech commented 5 years ago

I assume you are running on Windows? Which shell do you use for the terminal in VS Code?

eiredrake commented 5 years ago

Had to pull it up but looks like the default on my system is powershell and yes, windows. Just tried it with the cmd and same effect.

eiredrake commented 5 years ago

Additional info:

Tried another console progressbar. Same exact thing happened.

Also noted that running the app in either a command window or powershell works just fine. It only crashes when you run in inside VS code. Presumably there's some sort of difference in the way it handles consoles or something.

Mpdreamz commented 4 years ago

pbar-vscode

Closing this because it seems the terminal emulator in VS Code seems to have caught up.

Keep an eye on new release (>4.3.0) and let me know if the problem persists.

Thanks for reporting this one @eiredrake