Skip to content

System.Console.TreatControlCAsInput is backwards in .NET 5 RC.1 #42423

Closed

Description

@TylerLeonhardt

Description

See the following code:

using System;
using System.Threading;

var a = Console.TreatControlCAsInput;
Console.TreatControlCAsInput = true;

var key = Console.ReadKey(true);
Console.WriteLine("KEY: " + key.Key);
Console.WriteLine("MODS: " + key.Modifiers);

Console.TreatControlCAsInput = a;

Now run dotnet run and type Ctrl+C

You would expect to see:

KEY: C
MODS: Control

because TreatControlCAsInput is true, but you don't - it interupts the process.

Now set this instead in the example above

Console.TreatControlCAsInput = false;

Now run dotnet run and type Ctrl+C... you get:

KEY: C
MODS: Control

when I would expect the process to be interupted.

Configuration

  • Which version of .NET is the code running on? .NET 5 RC1
  • What OS and version, and what distro if applicable? macOS Catalina
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? No. It could be others. Not sure.

Regression?

Yes. This worked in preview 8. Setting:

Console.TreatControlCAsInput = true;

would allow ReadKey to return a KeyInfo and

Console.TreatControlCAsInput = false;

would cause Ctrl+C to interupt the process.

Other information

Activity

  1. added
    untriaged
    on Sep 18, 2020
  2. added this to the 5.0.0 milestone on Sep 18, 2020
  3. tmds commented on Sep 18, 2020

    @tmds
    Member

    The logic got inverted unintentionally in #39206. This PR will restore it: #42432.

  4. removed
    untriaged
    on Sep 18, 2020
  5. ghost locked as resolved and limited conversation to collaborators on Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions