Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console.ReadKey should not throw when read returns 0 records #98684

Merged
merged 1 commit into from
May 22, 2024

Commits on Feb 20, 2024

  1. Console.ReadKey should not throw when read returns 0 records

    This change fixes a problem where Console.ReadKey inappropriately throws
    an InvalidOperationException.
    
    The Console.ReadKey function can throw an InvalidOperationException when
    the "application does not have a console or when console input has been
    redirected". That makes sense.
    
    However, there is *another* case where it throws an
    InvalidOperationException, which happens when there are multiple
    processes attached to the same console, which are waiting for input, and
    one dies or is killed. In this case, the native read function returns a
    "success" return code, but the "out" parameter indicating the number of
    records read is 0, and in this case, Console.ReadKey is throwing, but it
    should not be.
    
    Note that this behavior of the underlying platform is "almost certainly"
    a bug (microsoft/terminal#15859); however, it
    is longstanding behavior, so we would like to avoid blowing up apps who
    have the misfortune of stumbling into this situation.
    
    More details in the linked Issue:
    
    Fix dotnet#88697
    jazzdelightsme committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    c04ebb0 View commit details
    Browse the repository at this point in the history