IVsaCodeItem.AddEventSource Method
Adds an event source to the code item. The code item uses the event source to hook up an event to the named event source by calling the IVsaSite.GetEventSourceInstance method, which is implemented by the host.
public: void AddEventSource(
String* eventSourceName,
String* eventSourceType
);
public void AddEventSource(
string EventSourceName,
string EventSourceType
);
MustOverride Public Sub AddEventSource(_
ByVal EventSourceName As String, _
ByVal EventSourceType As String _
)
Parameters
eventSourceName
A programmatic name of the event source.eventSourceType
The type name of the event source.
Remarks
The script engine uses information provided by the AddEventSource method to hook up events to the named event source. It obtains event sources by calling the IVsaSite.GetEventSourceInstance method, which is implemented by the host. The AddEventSource method creates a class that handles events raised by a host-provided object.
Note
The Jscript .NET script engine does not support this method. In cases where the Jscript .NET engine must hook up an event, you must do so using a global item. Rather than event sources, the Jscript .NET engine uses AppGlobal item types. For more information, see VsaItemType Enumeration.
Within the code item, you can access the event source object by name, and, once accessed, you can write event handlers against the object. The event source type is passed as a string rather than as a Type object to facilitate implementing event sources by unmanaged hosts.
The compiler uses the eventSourceType parameter to bind to methods provided by the type. It is also used later when the script engine calls the IVsaSite.GetEventSourceInstance method to request an instance of the Type object.
For more information about the mechanisms for hooking up events for the script engine, see the IVsaSite.GetEventSourceInstance method.
The following table shows the exceptions that the AddEventSource method can throw.
Exception Type |
Condition |
---|---|
EngineClosed |
The IVsaEngine.Close method has been called and the engine is closed. |
EngineRunning |
The engine is running. |
EventSourceNameInUse |
The name of the event is already in use. |
EventSourceNameInvalid |
The name of the event source is not valid. |
EventSourceTypeInvalid |
The type of the event source is not valid. |