/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // OnLoadOptions is called in base.Initialize(), so we need to set up _buildOnSave_ now _dte = await GetServiceAsync(typeof(DTE)) as DTE; _events = _dte.Events; _events.DTEEvents.OnBeginShutdown += beginShutdown; _solutionEvents = _events.SolutionEvents; _solutionEvents.Opened += solutionOpened; _solutionEvents.AfterClosing += solutionClosed; await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); try { _buildOnSave_ = new BuildOnSave(this); } catch (Exception e) { Log.E(e, "setting up BuildOnSave failed"); throw; } await base.InitializeAsync(cancellationToken, progress); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // OnLoadOptions is called in base.Initialize(), so we need to set up _buildOnSave_ now _dte = (DTE) await GetServiceAsync(typeof(DTE)); _events = _dte.Events; _solutionEvents = _events.SolutionEvents; _solutionEvents.Opened += solutionOpened; _solutionEvents.AfterClosing += solutionClosed; try { var commandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; // BuildOnSave constructor calls GetService() indirectly, so according to MS a // switch to the main thread is required. // Now I am asking why we need InitializeAsync() at all if we could just switch // to the main thread? await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _buildOnSave_ = new BuildOnSave(_dte, commandService); } catch (Exception e) { Log.E(e, "setting up BuildOnSave failed"); throw; } await base.InitializeAsync(cancellationToken, progress); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { // OnLoadOptions is called in base.Initialize(), so we need to set up _buildOnSave_ now _dte = GetService(typeof (DTE)) as DTE; _events = _dte.Events; _solutionEvents = _events.SolutionEvents; _solutionEvents.Opened += solutionOpened; _solutionEvents.AfterClosing += solutionClosed; try { _buildOnSave_ = new BuildOnSave(this); } catch (Exception e) { Log.E(e, "setting up BuildOnSave failed"); throw; } base.Initialize(); }