Skip to main content

Create Event Trigger

  • 2 minutes to read

Purpose

This Code Provider creates a method called event trigger, which is used to raise the event. The event trigger creates the event instance, ensures it is not null and raises the event using the parameters passed to the event trigger (sender and event arguments).

Availability

Available when the caret is on the event name in its declaration.

Usage

  1. Place the caret on the event name in its declaration.

    Note

    The blinking cursor shows the caret’s position at which the Code Provider is available.

    public class Alarm {
        public event EventHandler AlarmEvent;
        // ...
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Create Event Trigger from the menu.

After execution, the Code Provider creates a new method in your class. Use this method to raise the event.

public class Alarm {
     protected virtual void OnAlarmEvent(object sender, EventArgs e) {
         AlarmEvent?.Invoke(sender, e);
     }
     public event EventHandler AlarmEvent;
    // ...
}