On Thu, 2007-12-20 at 18:56 +0100, pablosantosluac wrote:
> I've found the following code to set a Control-C handler on a .NET 1.1 
> application.
> 
> http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx
> 
> Is there a way to do the same on Linux/Mono?

You can use signal(2), which is helpfully exposed by Mono.Posix.dll.

See the attached program.

 - Jon

// traps Ctrl+C
// To compile: mcs -r:Mono.Posix ctrlc.cs
using System;
using System.Threading;
using Mono.Unix.Native;

class Test {
	static volatile bool ctrl_c_pressed;

	static void handler (int sig)
	{
		ctrl_c_pressed = true;
	}

	public static void Main ()
	{
		Stdlib.signal (Signum.SIGINT, handler);

		Console.WriteLine ("Press Ctrl+C to terminate app.");
		while (!ctrl_c_pressed) {
			Thread.Sleep (1);
		}
		Console.WriteLine ("Finished.");
	}
}

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to