public override void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { base.OnConnection(application, connectMode, addInInst, ref custom); this._buildEvents = this.ApplicationObject.Events.BuildEvents; // this._buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(this._incrementor, (UIntPtr)ldftn(OnBuildBegin)); // this._buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(this._incrementor, (UIntPtr)ldftn(OnBuildDone)); _buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(_incrementor.OnBuildBegin); _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(_incrementor.OnBuildDone); if (connectMode == ext_ConnectMode.ext_cm_Startup) { Logger.Write("Checking online for a new version of BuildVersionIncrement.", LogLevel.Debug); try { VersionChecker versionChecker = this.GetVersionChecker(); versionChecker.CheckForNewVersionComplete += new EventHandler <VersionCheckerEventArgs>(this.VersionChecker_CheckForNewVersionComplete); versionChecker.CheckForNewVersionASync(); } catch (Exception) { } this._incrementor.InitializeIncrementors(); } }
private BuildEvents _buildEvents; // To prevent garbage collection of our events /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public override void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { base.OnConnection(application, connectMode, addInInst, ref custom); // If you plan to use this addin with visual studio 2005 sp1 from the command line you'll need the // following fix. // http://support.microsoft.com/kb/934517 // https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=5635 _buildEvents = ApplicationObject.Events.BuildEvents; // Add a ref to the buildevents to prevent a gc _buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(_incrementor.OnBuildBegin); _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(_incrementor.OnBuildDone); if (connectMode == ext_ConnectMode.ext_cm_Startup) { #if DEBUG if (true) #else if (DateTime.Now.Subtract(GlobalAddinSettings.Default.LastVersionCheck).Days > 1) #endif { Logger.Write("Checking online for a new version of BuildVersionIncrement.", LogLevel.Debug); try { VersionChecker versionChecker = GetVersionChecker(); versionChecker.CheckForNewVersionComplete += new EventHandler <VersionCheckerEventArgs>(VersionChecker_CheckForNewVersionComplete); versionChecker.CheckForNewVersionASync(); } catch (Exception) { // Die without a sound } } this._incrementor.InitializeIncrementors(); } }