Click or drag to resize

Events Class

Defines a set of consumable events that can be raised by a console application.
Inheritance Hierarchy
SystemObject
  GSF.ConsoleEvents

Namespace: GSF.Console
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public static class Events
View Source

The Events type exposes the following members.

Methods
 NameDescription
Public methodStatic memberDisableRaisingEvents Enables the raising of console application Events.
Public methodStatic memberEnableRaisingEvents Enables the raising of console application Events. Prior to calling this method, handlers must be defined for the Events raised by a console application.
Top
Events
 NameDescription
Public eventStatic memberBreakKeyPress Occurs when CTRL+BREAK signal is received from keyboard input.
Public eventStatic memberCancelKeyPress Occurs when CTRL+C signal is received from keyboard input.
Public eventStatic memberConsoleClosing Occurs when the user closes the console application window.
Public eventStatic memberSystemShutdown Occurs when the system is shutting down.
Public eventStatic memberUserLoggingOff Occurs when the user is logging off.
Top
Remarks
Note that no events will be raised by this class when running under Mono deployments, the class remains available in the Mono build as a stub to allow existing code to still compile and run.
Example
This example shows how to subscribe to console application events:
C#
using System;
using GSF.Console;

class Program
{
    static void Main(string[] args)
    {
        // Subscribe to console events.
        Events.CancelKeyPress += Events_CancelKeyPress;
        Events.ConsoleClosing += Events_ConsoleClosing;
        Events.EnableRaisingEvents();

        Console.ReadLine();
    }

    static void Events_CancelKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Abort processing.
    }

    static void Events_ConsoleClosing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Put clean-up code.
    }
}
See Also