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

Weeble clockworksaint at gmail.com
Fri May 20 06:41:06 EDT 2011


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?


More information about the Mono-list mailing list