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.
[Visual Basic] Sub AddEventSource( _ ByVal eventSourceName As String, _ ByVal eventSourceType As String _ ) [C#] void AddEventSource( string eventSourceName, string eventSourceType ); [C++] void AddEventSource( String* eventSourceName, String* eventSourceType ); [JScript] function AddEventSource( eventSourceName : String, eventSourceType : String );
- A programmatic name of the event source.
- The type name of the event source.
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.
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.
|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.|
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family