Bugzilla – Bug 315598
ctrl+c on consoleapp using SetConsoleCtrlHandler leads to mono error popup
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by monobugs@radeldudel.de 2004-07-26 10:09:04 MST ---- 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. ---- Additional Comments From bmaurer@users.sf.net 2004-11-05 23:56:30 MST ---- The issue here is that SetConsoleCtrlHandler calls back to managed code on a thread that we have not attached to. We don't/won't support this ---- Additional Comments From kornelpal@hotmail.com 2005-08-26 06:19:08 MST ---- https://bugzilla.novell.com/show_bug.cgi?id=MONO75836 was reported after this one but there is the discussion about this bug. The bug is fixed. ---- Additional Comments From kornelpal@hotmail.com 2005-08-26 06:20:03 MST ---- *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO75836 *** Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Server 2003</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other". This bug was marked DUPLICATE in the database it was moved from. Changing resolution to "MOVED"