# Establish Console Event Handlers

Control-C event handling is basically not reliable due to the threaded nature of processes executing on the Windows operating systems. Depending on what is happening at the instant a user types the Control-C, an event handler may or may not get the opportunity to execute. In any case, there are two ways to establish a handler if you want to do so. You can use the Windows* API routine SetConsoleCtrlHandler directly or you can use SIGNALQQ to establish a handler for the C `SIGINT` or `SIGBREAK` signals.

The Fortran run-time system establishes a console event handler through a call to SetConsoleCtrlHandler as part of its run-time initialization processing. See Default Console Event Handling for a description of this handler's behavior.

If you call SetConsoleCtrlHandler to establish your own event handler, your handler will be called first on console events.

If you establish a handler through SIGNALQQ with `SIGINT` or `SIGBREAK`, the C run-time system will establish its own internal handler for console events through a call to SetConsoleCtrlHandler, and it will record your routine as the desired action to take upon occurrence of an event. When an event is delivered to the C run-time handler, it will reset the action for the signal to `SIG_DFL` and then call your handler routine.

You must call SIGNALQQ again to reset the action to your routine if you want to continue from the control event. Your handler is called with the signal code (either `SIGINT` or `SIGBREAK`) as the argument. After your routine returns to the C run-time event handler, the C handler will return the value TRUE to the operating system indicating the event has been handled.

Parent topic: Advanced Exception and Termination Handling

## See Also

SIGNALQQ
Default Console Event Handling