[Mono-list] Cross-platform ctrl-c handling in console app

Miguel de Icaza miguel at xamarin.com
Fri May 20 13:12:49 EDT 2011


Hello,

   That is how the cancelled event works on Linux.   I used this in the REPL
to interrupt an ongoing computation, see:

mono/mcs/tools/csharp/getline.cs

On Fri, May 20, 2011 at 6:41 AM, Weeble <clockworksaint at gmail.com> wrote:

> What's a good way to write a cross-platform (for at least Windows and
> Linux, anyway) console app that terminates cleanly when the user
> presses ctrl+c? On Windows under .NET I can register an event-handler
> for Console.CancelKeyPressed. I assume this would work with Mono on
> Windows as well, but Mono on Linux doesn't seem to raise this event
> when the process receives SIGINT, which I would consider to be the
> analogous scenario. It looks like to handle SIGINT I would need to use
> Mono.Unix.UnixSignal from Mono.Posix. Can I write one assembly that
> does all of this? What's the best way to detect at run-time whether
> I'm running on Windows or Posix? Will anything bad happen on Windows
> (either at build-time or at run-time) if my assembly references
> Mono.Posix?
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110520/dea8e2c9/attachment.html 


More information about the Mono-list mailing list