Objective
In the last chapter add-in operation mechanism parsing (above), I analyzed the code generated by the Add-in Wizard, from which we know that as long as we create a class library, it contains the class that implements the IDTExtensibility2 interface, and then establishes the. AddIn configuration file, We can achieve a add-in. This paper will further introduce the events and life cycle of add-in, and lay a foundation for future development.
Add-in's Events
Add-in is an event-driven event that can be guessed by loading, unloading, state change, and so on. In fact, these events are related to the IDTExtensibility2 interface, which is the 5 methods of the interface:
If you want to understand how these methods are executed, one way is to add a messagebox to these methods and then do something with Add-in Manager to observe the execution of the event. Now use the Add-in Wizard to create a simple add-in, named Lifecycleaddin, do not choose to display commands in the Tools menu, and do not choose to load on vs startup. Then simplify the code for the Connect class:
C # code-add-in Event Demo
///<summary>the object for Implementing a add-in.</summary>
public class Connect:idtextensib Ility2
{
Public Connect ()
{
}
///<summary>
///receives Notif Ication that's the add-in is being loaded.
///</summary>
public void OnConnection (object Application,ext_connectmode connectmode,
Object Addininst,ref Array Custom)
{
_applicationobject = (DTE2) application;
_addInInstance = (AddIn) addininst;
MessageBox.Show (string. Format ("Event:onconnection,connectmode: {0}", ConnectMode));
}
///<summary>
///receives notification This add-in is being unloaded.
</summary>
public void OnDisconnection (Ext_disconnectmode disconnectmode,ref Array Custom)
{
MessageBox.Show (string. Format ("Event:ondisconnection,connectmode: {0}", DisconNectmode));
}
///<summary>
///receives notification when the collection of Add-ins has Chang ed.
///</summary>
public void OnAddInsUpdate (ref Array Custom)
{
MessageBox . Show ("OnAddInsUpdate");
}
///<summary>
///receives notification that host application has completed Loading.
///</summary>
public void OnStartupComplete (ref Array Custom)
{
MessageBox . Show ("OnStartupComplete");
}
///<summary>
///receives notification that this host application is being Unloa Ded.
///</summary>
public void OnBeginShutdown (ref Array Custom)
{
Messagebox.s How ("OnBeginShutdown");
}
Private DTE2 _applicationobject
Private AddIn _addininstance;
}