Visual Studio 2008 Scalability Development (iii): Analysis of the operating mechanism of add-in (next)

Source: Internet
Author: User

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.