Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Added VS.Initialize and VS.JoinableTaskFactory #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Community.VisualStudio.Toolkit;

namespace Microsoft.VisualStudio.Shell
{
Expand All @@ -14,7 +15,7 @@ public static class TaskExtensions
/// </remarks>
public static void FireAndForget(this System.Threading.Tasks.Task task)
{
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
VS.JoinableTaskFactory.RunAsync(async () =>
{
try
{
Expand Down
18 changes: 18 additions & 0 deletions src/Community.VisualStudio.Toolkit.Shared/VS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EnvDTE80;
using Microsoft;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;

namespace Community.VisualStudio.Toolkit
{
Expand All @@ -11,6 +12,23 @@ namespace Community.VisualStudio.Toolkit
/// </summary>
public static class VS
{
private static JoinableTaskFactory _jtf = ThreadHelper.JoinableTaskFactory;

/// <summary>
/// Initializes the entry point.
/// This is an optional but recommended step in order to optimize use of the JoinableTaskFactory.
/// Call this method at the start of the extension's AsyncPackage's InitializeAsync method and pass
/// the AsyncPackage.JoinableTaskFactory as the argument.
/// </summary>
/// <param name="jtf">The JoinableTaskFactory instance from the extension's AsyncPackage.</param>
public static void Initialize(JoinableTaskFactory jtf)
{
_jtf = jtf;
}

/// <summary>The JoinableTaskFactory either from the extension's package or from ThreadHelper. See <see cref="Initialize(JoinableTaskFactory)"/>.</summary>
public static JoinableTaskFactory JoinableTaskFactory => _jtf;

/// <summary>A collection of services related to the command system.</summary>
public static Commanding Commanding => new();

Expand Down
2 changes: 2 additions & 0 deletions test/VSSDK.TestExtension/VSSDK.TestExtensionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public sealed class TestExtensionPackage : AsyncPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
VS.Initialize(JoinableTaskFactory);

await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
await TestCommand.InitializeAsync(this);
await RunnerWindowCommand.InitializeAsync(this);
Expand Down