|
3 | 3 | using System.Diagnostics;
|
4 | 4 | using System.Globalization;
|
5 | 5 | using System.Runtime.InteropServices;
|
| 6 | +using System.Threading; |
| 7 | +using System.Threading.Tasks; |
6 | 8 | using Microsoft.VisualStudio;
|
7 | 9 | using Microsoft.VisualStudio.Shell;
|
8 | 10 | using Microsoft.VisualStudio.Shell.Interop;
|
9 | 11 |
|
10 | 12 | namespace ArrayVisualizerExt
|
11 | 13 | {
|
12 |
| - /// <summary> |
13 |
| - /// This is the class that implements the package exposed by this assembly. |
14 |
| - /// |
15 |
| - /// The minimum requirement for a class to be considered a valid package for Visual Studio |
16 |
| - /// is to implement the IVsPackage interface and register itself with the shell. |
17 |
| - /// This package uses the helper classes defined inside the Managed Package Framework (MPF) |
18 |
| - /// to do it: it derives from the Package class that provides the implementation of the |
19 |
| - /// IVsPackage interface and uses the registration attributes defined in the framework to |
20 |
| - /// register itself and its components with the shell. |
21 |
| - /// </summary> |
22 |
| - // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is |
23 |
| - // a package. |
24 |
| - [PackageRegistration(UseManagedResourcesOnly = true)] |
25 |
| - // This attribute is used to register the information needed to show the this package |
26 |
| - // in the Help/About dialog of Visual Studio. |
| 14 | + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] |
27 | 15 | [InstalledProductRegistration("Array Visualizer",
|
28 |
| - "Visualizes 1D, 2D, 3D and 4D arrays and SharpDX Vectors and Matrices", "1.0", IconResourceID = 400)] |
29 |
| - // This attribute is needed to let the shell know that this package exposes some menus. |
| 16 | + "Visualizes 1D, 2D, 3D and 4D arrays and SharpDX Vectors and Matrices", "1.7", IconResourceID = 400)] |
30 | 17 | [ProvideMenuResource("Menus.ctmenu", 1)]
|
31 |
| - // This attribute registers a tool window exposed by this package. |
32 | 18 | [ProvideToolWindow(typeof(ArrayVisualizerToolWindow))]
|
33 | 19 | [Guid(GuidList.GuidArrayVisualizerExtPkgString)]
|
34 |
| - public sealed class ArrayVisualizerExtPackage : Package |
| 20 | + public sealed class ArrayVisualizerExtPackage : AsyncPackage |
35 | 21 | {
|
36 | 22 | /// <summary>
|
37 | 23 | /// Default constructor of the package.
|
@@ -77,20 +63,23 @@ private void ShowToolWindow(object sender, EventArgs e)
|
77 | 63 | /// Initialization of the package; this method is called right after the package is sited, so this is the place
|
78 | 64 | /// where you can put all the initialization code that rely on services provided by VisualStudio.
|
79 | 65 | /// </summary>
|
80 |
| - protected override void Initialize() |
| 66 | + protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) |
81 | 67 | {
|
82 | 68 | Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}",
|
83 | 69 | ToString()));
|
84 |
| - base.Initialize(); |
| 70 | + Initialize(); |
| 71 | + |
| 72 | + progress.Report(new ServiceProgressData("Registering menu commands for ArrayVisualizer.")); |
85 | 73 |
|
86 | 74 | // Add our command handlers for menu (commands must exist in the .vsct file)
|
87 |
| - ThreadHelper.ThrowIfNotOnUIThread(); |
88 |
| - if (GetService(typeof(IMenuCommandService)) is OleMenuCommandService mcs) |
| 75 | + if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService mcs) |
89 | 76 | {
|
90 | 77 | // Create the command for the tool window
|
91 | 78 | CommandID toolwndCommandId = new CommandID(GuidList.GuidArrayVisualizerExtCmdSet,
|
92 | 79 | (int) PkgCmdIdList.ArrayVisualizerTool);
|
93 | 80 | MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandId);
|
| 81 | + |
| 82 | + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); |
94 | 83 | mcs.AddCommand(menuToolWin);
|
95 | 84 | //GlobalVars.menuToolWin = menuToolWin;
|
96 | 85 | }
|
|
0 commit comments