/// <summary> /// Enables the raising of console application <see cref="Events"/>. /// </summary> /// <remarks> /// This method is currently ignored under Mono deployments. /// </remarks> public static void DisableRaisingEvents() { s_handler = HandleConsoleWindowEvents; #if !MONO SetConsoleWindowEventRaising(s_handler, false); #endif }
/// <summary> /// Enables the raising of console application <see cref="Events"/>. Prior to calling this method, handlers /// must be defined for the <see cref="Events"/> raised by a console application. /// </summary> /// <remarks> /// This method is currently ignored under Mono deployments. /// </remarks> public static void EnableRaisingEvents() { s_handler = HandleConsoleWindowEvents; #if !MONO // Member variable is used here so that the delegate is not garbage collected by the time it is called // by WIN API when any of the control events take place. // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=996045&SiteID=1 SetConsoleWindowEventRaising(s_handler, true); #endif }
private static extern bool SetConsoleWindowEventRaising(ConsoleWindowEventHandler handler, [MarshalAs(UnmanagedType.Bool)] bool enable);
private static extern bool SetConsoleWindowEventRaising(ConsoleWindowEventHandler handler, bool enable);
/// <summary> /// Enables the raising of console application <see cref="Events"/>. /// </summary> public static void DisableRaisingEvents() { m_handler = HandleConsoleWindowEvents; SetConsoleWindowEventRaising(m_handler, false); }