Skip to content

Commit bf184f1

Browse files
Converted to AsyncPackage
[release]
1 parent da4b99d commit bf184f1

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/WebCompilerVsix/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class Logger
1212
private static IServiceProvider _provider;
1313
private static string _name;
1414

15-
public static void Initialize(IServiceProvider provider, string name)
15+
public static void Initialize(Microsoft.VisualStudio.Shell.Package provider, string name)
1616
{
1717
_provider = provider;
1818
_name = name;

src/WebCompilerVsix/WebCompilerPackage.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Runtime.InteropServices;
4+
using System.Threading;
5+
using System.Threading.Tasks;
46
using System.Windows.Threading;
57
using EnvDTE;
68
using EnvDTE80;
@@ -12,21 +14,23 @@
1214

1315
namespace WebCompilerVsix
1416
{
15-
[PackageRegistration(UseManagedResourcesOnly = true)]
17+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
1618
[InstalledProductRegistration("#110", "#112", Version, IconResourceID = 400)]
1719
[ProvideMenuResource("Menus.ctmenu", 1)]
1820
[Guid(PackageGuids.guidCompilerPackageString)]
19-
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
20-
public sealed class WebCompilerPackage : Package
21+
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
22+
public sealed class WebCompilerPackage : AsyncPackage
2123
{
2224
public const string Version = "1.4.167";
2325
public static DTE2 _dte;
2426
public static Package Package;
2527
private SolutionEvents _solutionEvents;
2628
private BuildEvents _buildEvents;
2729

28-
protected override void Initialize()
30+
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
2931
{
32+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
33+
3034
_dte = GetService(typeof(DTE)) as DTE2;
3135
Package = this;
3236

@@ -46,8 +50,6 @@ protected override void Initialize()
4650
RemoveConfig.Initialize(this);
4751
CompileAllFiles.Initialize(this);
4852
CleanOutputFiles.Initialize(this);
49-
50-
base.Initialize();
5153
}
5254

5355
private void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
@@ -74,15 +76,18 @@ public static bool IsDocumentDirty(string documentPath, out IVsPersistDocData pe
7476
}
7577
}
7678

77-
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
78-
[ProvideAutoLoad(UIContextGuids80.NoSolution)]
79-
public sealed class WebCompilerInitPackage : Package
79+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
80+
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
81+
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
82+
public sealed class WebCompilerInitPackage : AsyncPackage
8083
{
8184
public static Dispatcher _dispatcher;
8285
public static DTE2 _dte;
8386

84-
protected override void Initialize()
87+
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
8588
{
89+
await JoinableTaskFactory.SwitchToMainThreadAsync();
90+
8691
_dispatcher = Dispatcher.CurrentDispatcher;
8792
_dte = GetService(typeof(DTE)) as DTE2;
8893

src/WebCompilerVsix/WebCompilerVsix.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<Reference Include="Microsoft.VisualStudio.TextManager.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
210210
<Private>False</Private>
211211
</Reference>
212+
<Reference Include="Microsoft.VisualStudio.Threading, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
212213
<Reference Include="Microsoft.VisualStudio.Utilities, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
213214
<Private>False</Private>
214215
</Reference>

0 commit comments

Comments
 (0)