Event

Concrete implementation of the IEvent interface.

Inherits: IEvent

Description

The Event class allows you to create events.

Important points

  • It allows you to send asynchronous notifications to multiple subscribed listeners.

Constructors

Creates a new event and assigns its name.
Throws an Error if the name is null.

public Event(string name)

  • name: string - name of the event that is to be created.

Properties

Name

Gets the name of the event.

public string Name { get; }

Listeners

Gets all listeners registered in this event.

public List<IEventListener> Listeners { get; }

Instance methods

AddListener

Adds a listener to receive notifications when this event is fired.

public void AddListener(IEventListener listener)

NotifyAsync

Fires this event and notifies all registred listeners.
Throws an InvocationException if the event fails to be raised.

public void NotifyAsync(string correlationId, Parameters args)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • args: Parameters - parameters to raise this event with.

RemoveListener

Removes a listener, so that it no longer receives notifications for this event.

public void RemoveListener(IEventListener listener)

Example:

var event = new Event("my_event");
event.addListener(myListener);

event.notify("123", Parameters.FromTuples(
"param1", "ABC",   
<br>"param2", 123 ));

See also