Exemple #1
0
        /// <summary>
        /// Set the console's break handler
        /// </summary>
        /// <param name="handlerDelegate"></param>
        /// <exception cref="HostException">
        /// If Win32's SetConsoleCtrlHandler fails
        /// </exception>

        internal static void AddBreakHandler(BreakHandler handlerDelegate)
        {
            bool result = NativeMethods.SetConsoleCtrlHandler(handlerDelegate, true);

            if (result == false)
            {
                int err = Marshal.GetLastWin32Error();

                HostException e = CreateHostException(err, "AddBreakHandler",
                    ErrorCategory.ResourceUnavailable, ConsoleControlStrings.AddBreakHandlerExceptionMessage);
                throw e;
            }
        }
 public static extern bool SetConsoleCtrlHandler(BreakHandler handlerRoutine, bool add);
 internal static extern bool SetConsoleCtrlHandler(
     BreakHandler handlerRoutine,
     bool add
     );