/// <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 async override void Initialize() { _packageProvider = new PackageProviderService(this); DocumentManager = new DocumentManager(this); PackageCommands.Initialize(this); base.Initialize(); // Hook up event handlers await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { // Must save the solution events, otherwise it seems to get GC'd _solutionEvents = Environment.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.AfterClosing += OnSolutionClosed; }), DispatcherPriority.ApplicationIdle, null); }
/// <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) { // Switches to the UI thread in order to consume some services used in command initialization await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _packageProvider = new PackageProviderService(this); DocumentManager = new DocumentManager(this); PackageCommands.Initialize(this); await base.InitializeAsync(cancellationToken, progress); // Must save the solution events, otherwise it seems to get GC'd _solutionEvents = Environment.Events.SolutionEvents; // Hook up event handlers _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.AfterClosing += OnSolutionClosed; }