Bug 17085 - Console.SetForegroundColor breaks Control-C in web applications
Summary: Console.SetForegroundColor breaks Control-C in web applications
Status: RESOLVED FEATURE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.0.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-07 06:33 UTC by Federico Di Gregorio
Modified: 2014-02-12 09:45 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Federico Di Gregorio 2014-01-07 06:33:44 UTC
We are using fastcgi-mono-server4 both in development and production. The application can easily be interrupted from the console by sending a SIGINT (Control-C) unless Console.SetForegroundColor is used, in which case the application continues to work correctly but can't be interrupted anymore.

This can easily be reproduced as follow:

1) In Xamarin Studio/MonoDevelop create a new Web Application (the one with default page).

2) Add the following code to the Default.aspx.cs file, at the end of the button1Clicked method:

    Console.ForegroundColor = ConsoleColor.Cyan;
    Console.WriteLine("This should print in nice cyan color!");
    Console.ResetColor();

3) Go to the project directory and run:

    MONO_OPTIONS=--debug fastcgi-mono-server4 /socket=tcp:127.0.0.1:9000 /applications=/:.

   Control-C will correctly interrupt fastcgi-mono-server4.

4) Configure Apache or nginx to do FastCGI on localhost:9000 and load the root page a couple of times.

5) Now Control-C does nothing.
Comment 1 Miguel de Icaza [MSFT] 2014-02-11 21:48:01 UTC
This is correct.

When you use any of the "enhanced" Console methods (colors, single-keystroke read, go-to column/location) we enable the advanced console, and that one takes over C-c.

By design I am afraid.
Comment 2 Federico Di Gregorio 2014-02-12 03:32:50 UTC
That's OK (probably should be documented somewhere). I have two questions though:

1) how is one supposed to intercept C-c after the advanced console has been enabled?

2) Is it possible to disable it (after using the "enhanced" methods?
Comment 3 Miguel de Icaza [MSFT] 2014-02-12 09:45:14 UTC
You can use the Console's CancelKeyPress event.

There is no way to turn this off;   your best bet is to avoid using any of the new Console APIs, and instead use something like curses, or roll your own.