[Mono-bugs] [Bug 61951][Nor] New - ctrl+c on consoleapp using SetConsoleCtrlHandler leads to mono error popup

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 26 Jul 2004 10:09:05 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by monobugs@radeldudel.de.

http://bugzilla.ximian.com/show_bug.cgi?id=61951

--- shadow/61951	2004-07-26 10:09:05.000000000 -0400
+++ shadow/61951.tmp.2150	2004-07-26 10:09:05.000000000 -0400
@@ -0,0 +1,93 @@
+Bug#: 61951
+Product: Mono: Runtime
+Version: unspecified
+OS: 
+OS Details: Server 2003
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: monobugs@radeldudel.de               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: ctrl+c on consoleapp using SetConsoleCtrlHandler leads to mono error popup
+
+Description of Problem:
+
+I wrote a console-app. This app utilizes the win32-call 
+SetConsoleCtrlHandler to get notified about aborts, system shutdowns, ...
+
+When I use mono to start the app and press ctrl+c mono pops up an error 
+window 
+"** ERROR **: file mini.c: line 6508 (mono_get_lmf_addr): should not be 
+reached
+aborting..."
+
+On the same moment the program stops without getting notified of being 
+stopped and on the console prints this error: 
+"This application has requested the Runtime to terminate it in an unusual 
+way.
+Please contact the application's support team for more information."
+
+Steps to reproduce the problem:
+You need to compile the sample source to a console app, start it using 
+mono and press ctrl+c in the console while it is running to get the error 
+popup:
+--- console sample app
+using System;
+using System.Runtime.InteropServices;
+
+namespace Sam.CmdTestWait
+{
+ class MainClass
+ {
+  public enum XConsoleEvent
+  {
+   CTRL_C = 0,		// From wincom.h
+   CTRL_BREAK = 1,
+   CTRL_CLOSE = 2,
+   CTRL_LOGOFF = 5,
+   CTRL_SHUTDOWN = 6
+  }
+
+  private delegate bool ControlEventHandler( XConsoleEvent consoleEvent);
+		
+  [DllImport("kernel32.dll")]
+  static extern bool SetConsoleCtrlHandler(ControlEventHandler e, bool 
+add);
+
+  private static bool Handler( XConsoleEvent consoleEvent)
+  {
+   return true;
+  }
+
+  [STAThread]
+  static int Main(string[] args)
+  {
+   ControlEventHandler eventHandler= new ControlEventHandler(Handler);
+   SetConsoleCtrlHandler( eventHandler, true);
+
+   int countdown= 10;
+   while (countdown>0)
+   {
+    Console.WriteLine( countdown+"...");
+    System.Threading.Thread.Sleep( 1000);
+    countdown--;	
+   }
+   Console.WriteLine( "time over");
+   return rc;
+  }
+ }
+}
+--- end code
+
+Additional notes:
+Since this feature is using interop it might well be you don't care about 
+this bug, or don't want to cover it since to capture console events you 
+will need complete different approaches on Linux, so maybe this is no bug 
+at all, but only a windows feature not working on mono.
+But thats for the mono developers to decide, not for me.