private static async Task ExecuteAsync(AsyncPackage package, TimeLog log) { TimeSpan time = await log.ReadAsync(); VsShellUtilities.ShowMessageBox( package, $"This solution has been open for {time.TotalMinutes} minutes", nameof(TimeLog), OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); }
public static async Task InitializeAsync(AsyncPackage package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); TimeLog log = await package.GetServiceAsync <TimeLog, TimeLog>(); OleMenuCommandService commandService = await package.GetServiceAsync <IMenuCommandService, OleMenuCommandService>(); var menuCommandID = new CommandID(PackageGuids.TimeLogCmdSet, PackageIds.OpenTimeLog); var menuItem = new OleMenuCommand((s, e) => ExecuteAsync(package, log).ConfigureAwait(false), menuCommandID, false); commandService.AddCommand(menuItem); }
private async Task <bool> IsSolutionLoadedAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); var solService = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution; Assumes.Present(solService); _log = new TimeLog(solService); ErrorHandler.ThrowOnFailure(solService.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out var value)); return(value is bool isSolOpen && isSolOpen); }