2012-04-23 3 views

답변

0

당신은 Console.CancelKeyPress event을 사용할 수 있습니다 제공 할 수 있습니다.

이 이벤트는 System.ConsoleCancelEventHandler 및 System.ConsoleCancelEventArgs와 함께 사용됩니다. CancelKeyPress 이벤트를 사용하면 콘솔 응용 프로그램에서 CTRL + C 신호를 가로 채어 응용 프로그램이 을 계속 실행할지 또는 종료 할지를 결정할 수 있습니다.

+0

감사에서 온다, 나는 또한뿐만 아니라 Ctrl 키 C 다른 키보드 이벤트를 캡처 할 – Boardy

1

유닉스/리눅스에서 실행중인 내 리눅스 응용 프로그램에 Mono.UnixSignal

내가 이것을 사용을 사용하는 경우. 장점은 재부팅 또는 시스템 종료를 감지한다는 것입니다.

이 예는 제어 C는 예였다 this Mono FAQ page

// Catch SIGINT and SIGUSR1 
UnixSignal[] signals = new UnixSignal [] { 
    new UnixSignal (Mono.Unix.Native.Signum.SIGINT), 
    new UnixSignal (Mono.Unix.Native.Signum.SIGUSR1), 
}; 

Thread signal_thread = new Thread (delegate() { 
    while (true) { 
     // Wait for a signal to be delivered 
     int index = UnixSignal.WaitAny (signals, -1); 

     Mono.Unix.Native.Signum signal = signals [index].Signum; 

     // Notify the main thread that a signal was received, 
    // you can use things like: 
    // Application.Invoke() for Gtk# 
    // Control.Invoke on Windows.Forms 
    // Write to a pipe created with UnixPipes for server apps. 
    // Use an AutoResetEvent 

    // For example, this works with Gtk#  
    Application.Invoke (delegate() { ReceivedSignal (signal); } 
    }); 
관련 문제