public static async Task InitializeAsync(AsyncPackage Package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken); var CommandService = await Package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; _ = new WindowCommand(Package, CommandService); }
protected override async Task InitializeAsync ( CancellationToken Token, IProgress <ServiceProgressData> Progress ) { await base.InitializeAsync(Token, Progress); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Token); #region Events #region RunningDocumentTable var Table = new RunningDocumentTable(this); Table.Advise(new RunningDocTableEvents()); #endregion #region EnvDTE.Events var DTE = await Utils.GetDTEAsync(); Events = DTE.Events; DocumentEvents = Events.DocumentEvents; DocumentEvents.DocumentClosing += Document => { _ = Task.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (Document.Language != "C/C++") { return; } await TaskScheduler.Default; await File.Structure.Events.OnBeforeDocumentCloseAsync(); }, Token); }; WindowEvents = Events.WindowEvents; WindowEvents.WindowActivated += (GotFocus, LostFocus) => { if (GotFocus == LastWindowThatGotFocus) { return; } _ = Task.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (GotFocus.Document == null) { return; } if (GotFocus.Document.Language != "C/C++") { return; } await TaskScheduler.Default; LastWindowThatGotFocus = GotFocus; await File.Structure.Events.OnAfterWindowActivateAsync(); }, Token); }; #endregion await WindowCommand.InitializeAsync(this); #endregion }