Browse Source

Switch to AsyncPackage with background load

pull/1397/head
Sam Harwell 6 years ago
parent
commit
6a2eab2a52
  1. 3
      ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
  2. 5
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  3. 3
      ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
  4. 3
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs
  5. 36
      ILSpy.AddIn/ILSpyAddInPackage.cs

3
ILSpy.AddIn/Commands/OpenCodeItemCommand.cs

@ -18,6 +18,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
public OpenCodeItemCommand(ILSpyAddInPackage owner) public OpenCodeItemCommand(ILSpyAddInPackage owner)
: base(owner, PkgCmdIDList.cmdidOpenCodeItemInILSpy) : base(owner, PkgCmdIDList.cmdidOpenCodeItemInILSpy)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
} }
protected override void OnBeforeQueryStatus(object sender, EventArgs e) protected override void OnBeforeQueryStatus(object sender, EventArgs e)
@ -185,6 +186,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
internal static void Register(ILSpyAddInPackage owner) internal static void Register(ILSpyAddInPackage owner)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
instance = new OpenCodeItemCommand(owner); instance = new OpenCodeItemCommand(owner);
} }
} }

5
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

@ -32,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected ILSpyCommand(ILSpyAddInPackage owner, uint id) protected ILSpyCommand(ILSpyAddInPackage owner, uint id)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
this.owner = owner; this.owner = owner;
CommandID menuCommandID = new CommandID(GuidList.guidILSpyAddInCmdSet, (int)id); CommandID menuCommandID = new CommandID(GuidList.guidILSpyAddInCmdSet, (int)id);
OleMenuCommand menuItem = new OleMenuCommand(OnExecute, menuCommandID); OleMenuCommand menuItem = new OleMenuCommand(OnExecute, menuCommandID);
@ -120,6 +122,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
public OpenILSpyCommand(ILSpyAddInPackage owner) public OpenILSpyCommand(ILSpyAddInPackage owner)
: base(owner, PkgCmdIDList.cmdidOpenILSpy) : base(owner, PkgCmdIDList.cmdidOpenILSpy)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
} }
protected override void OnExecute(object sender, EventArgs e) protected override void OnExecute(object sender, EventArgs e)
@ -129,6 +132,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
internal static void Register(ILSpyAddInPackage owner) internal static void Register(ILSpyAddInPackage owner)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
instance = new OpenILSpyCommand(owner); instance = new OpenILSpyCommand(owner);
} }
} }

3
ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
public OpenProjectOutputCommand(ILSpyAddInPackage owner) public OpenProjectOutputCommand(ILSpyAddInPackage owner)
: base(owner, PkgCmdIDList.cmdidOpenProjectOutputInILSpy) : base(owner, PkgCmdIDList.cmdidOpenProjectOutputInILSpy)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
} }
protected override void OnBeforeQueryStatus(object sender, EventArgs e) protected override void OnBeforeQueryStatus(object sender, EventArgs e)
@ -36,6 +37,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
internal static void Register(ILSpyAddInPackage owner) internal static void Register(ILSpyAddInPackage owner)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
instance = new OpenProjectOutputCommand(owner); instance = new OpenProjectOutputCommand(owner);
} }
} }

3
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -17,6 +17,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
public OpenReferenceCommand(ILSpyAddInPackage owner) public OpenReferenceCommand(ILSpyAddInPackage owner)
: base(owner, PkgCmdIDList.cmdidOpenReferenceInILSpy) : base(owner, PkgCmdIDList.cmdidOpenReferenceInILSpy)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
} }
protected override void OnBeforeQueryStatus(object sender, EventArgs e) protected override void OnBeforeQueryStatus(object sender, EventArgs e)
@ -87,6 +88,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
internal static void Register(ILSpyAddInPackage owner) internal static void Register(ILSpyAddInPackage owner)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
instance = new OpenReferenceCommand(owner); instance = new OpenReferenceCommand(owner);
} }
} }

36
ILSpy.AddIn/ILSpyAddInPackage.cs

@ -3,6 +3,8 @@ using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.ComponentModel.Design; using System.ComponentModel.Design;
using System.Threading;
using Microsoft;
using Microsoft.VisualStudio; using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell;
@ -11,6 +13,7 @@ using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.LanguageServices; using Microsoft.VisualStudio.LanguageServices;
using EnvDTE; using EnvDTE;
using System.Collections.Generic; using System.Collections.Generic;
using Task = System.Threading.Tasks.Task;
namespace ICSharpCode.ILSpy.AddIn namespace ICSharpCode.ILSpy.AddIn
{ {
@ -26,15 +29,15 @@ namespace ICSharpCode.ILSpy.AddIn
/// </summary> /// </summary>
// This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
// a package. // a package.
[PackageRegistration(UseManagedResourcesOnly = true)] [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
// This attribute is used to register the information needed to show this package // This attribute is used to register the information needed to show this package
// in the Help/About dialog of Visual Studio. // in the Help/About dialog of Visual Studio.
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
// This attribute is needed to let the shell know that this package exposes some menus. // This attribute is needed to let the shell know that this package exposes some menus.
[ProvideMenuResource("Menus.ctmenu", 1)] [ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(GuidList.guidILSpyAddInPkgString)] [Guid(GuidList.guidILSpyAddInPkgString)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string)] [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class ILSpyAddInPackage : Package public sealed class ILSpyAddInPackage : AsyncPackage
{ {
/// <summary> /// <summary>
/// Default constructor of the package. /// Default constructor of the package.
@ -65,19 +68,24 @@ namespace ICSharpCode.ILSpy.AddIn
/// Initialization of the package; this method is called right after the package is sited, so this is the place /// 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. /// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary> /// </summary>
protected override void Initialize() protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{ {
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); Debug.WriteLine($"Entering {nameof(InitializeAsync)}() of: {this}");
base.Initialize();
await base.InitializeAsync(cancellationToken, progress);
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel));
Assumes.Present(componentModel);
// Add our command handlers for menu (commands must exist in the .vsct file) // Add our command handlers for menu (commands must exist in the .vsct file)
this.menuService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; this.menuService = (OleMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService));
Assumes.Present(menuService);
var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel));
this.workspace = componentModel.GetService<VisualStudioWorkspace>(); this.workspace = componentModel.GetService<VisualStudioWorkspace>();
Assumes.Present(workspace);
if (menuService == null || workspace == null)
return;
OpenILSpyCommand.Register(this); OpenILSpyCommand.Register(this);
OpenProjectOutputCommand.Register(this); OpenProjectOutputCommand.Register(this);
@ -88,16 +96,22 @@ namespace ICSharpCode.ILSpy.AddIn
public void ShowMessage(string format, params object[] items) public void ShowMessage(string format, params object[] items)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, format, items); ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, format, items);
} }
public void ShowMessage(OLEMSGICON icon, string format, params object[] items) public void ShowMessage(OLEMSGICON icon, string format, params object[] items)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, icon, format, items); ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, icon, format, items);
} }
public int ShowMessage(OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon, string format, params object[] items) public int ShowMessage(OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon, string format, params object[] items)
{ {
ThreadHelper.ThrowIfNotOnUIThread();
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
Guid clsid = Guid.Empty; Guid clsid = Guid.Empty;
int result; int result;

Loading…
Cancel
Save