Share via


IVsaSite.GetEventSourceInstance Method

Gets a reference to an event source previously added to a script engine using the IVsaCodeItem.AddEventSource method.

public: Object* GetEventSourceInstance( 
   String*  ItemName,
   String*  EventSourceName
);
public object GetEventSourceInstance( 
   string  ItemName,
   string  EventSourceName
);
MustOverride Public Function GetEventSourceInstance( _ 
   ByVal  ItemName As String, _
   ByVal  EventSourceName As String _
) As Object

Parameters

  • itemName
    The specified item name.

  • eventSourceName
    The specified event source name.

Return Value

Returns the event source to the engine.

Remarks

Binding user code to events in Script for the .NET Framework is a relatively simple process.

  1. The host adds event sources to user-implemented event handlers by calling the IVsaCodeItem.AddEventSource method, or by adding an AppGlobal object for languages that do not support implicit event binding, and passing in the name of the event source and its type.

  2. Using this information, the engine compiles the code to the event-source item and generates any necessary start-up code to enable events at runtime.

  3. When the host calls the IVsaEngine.Run method, the engine calls back on the IVsaSite.GetEventSourceInstance method and pulls the event sources into the engine.

  4. Once it has a reference to the event source, the engine can hook up the user code and enable the engine to respond to events raised by the host object.

Because multiple items with identical names may have been added to more than one code item, the name of the item requesting the event source is given as the itemName parameter. The eventSourceName parameter is the same as the eventSourceName parameter originally passed to the engine in the call to the IVsaCodeItem.AddEventSource method.

The itemName and eventSourceName parameters must be valid names previously added by the host.

The following table shows the exceptions that the GetEventSourceInstance method can throw.

Exception Type

Condition

EventSourceInvalid

The specified event source does not exist for the given item.

CallbackUnexpected

The host was not expecting a call at this time.

See Also

Reference

IVsaCodeItem.AddEventSource Method

IVsaSite Interface

IVsaSite.GetEventSourceInstance

IVsaEngine.Run Method