Skip to content

Commit 7c4e069

Browse files
authored
Fix hang during project creation (#901)
1 parent 1d0286c commit 7c4e069

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

vs-extension.shared/MessageCentre/MessageCentre.cs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,36 @@ public class MessageCentre
3434
public static string MessageStartSearchingDevices = "[.NET nanoFramework] Start searching for devices in the background...";
3535
public static string MessageCompletedDevicesSearch = "[.NET nanoFramework] Devices search completed.";
3636

37-
public static System.Threading.Tasks.Task InitializeAsync(AsyncPackage package, string name)
37+
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package, string name)
3838
{
39-
return ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
40-
{
41-
// seems OK to call these API here without switching to the main thread as we are just getting the service not actually accessing the output window
42-
#pragma warning disable VSTHRD010
43-
_outputWindow = await package.GetServiceAsync(typeof(SVsOutputWindow)) as IVsOutputWindow;
44-
Assumes.Present(_outputWindow);
45-
46-
_statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar;
47-
Assumes.Present(_statusBar);
48-
#pragma warning restore VSTHRD010
49-
50-
_paneName = name;
51-
52-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
53-
54-
// get VS debug pane
55-
Guid tempId = VSConstants.GUID_OutWindowDebugPane;
56-
_outputWindow.GetPane(ref tempId, out _debugPane);
57-
58-
// create nanoFramework pane
59-
tempId = s_DeploymentMessagesPaneGuid;
60-
_outputWindow.CreatePane(ref tempId, _paneName, 1, 0);
61-
_outputWindow.GetPane(ref tempId, out _nanoFrameworkMessagesPane);
62-
63-
// create firmware update manager pane
64-
tempId = s_FirmwareUpdatManagerPane;
65-
_outputWindow.CreatePane(ref tempId, ".NET nanoFramework Firmware Update Manager", 1, 0);
66-
_outputWindow.GetPane(ref tempId, out _firmwareUpdatManager);
67-
68-
// create virtual device manager pane
69-
tempId = s_VirtualDevicePane;
70-
_outputWindow.CreatePane(ref tempId, ".NET nanoFramework Virtual Device", 1, 0);
71-
_outputWindow.GetPane(ref tempId, out _virtualDevice);
72-
73-
OutputWelcomeMessage();
74-
75-
}).Task;
39+
// Switch to the UI thread before retrieving these STA services
40+
// to reduce the # of thread switches needed
41+
await package.JoinableTaskFactory.SwitchToMainThreadAsync();
42+
43+
_outputWindow = await package.GetServiceAsync<SVsOutputWindow, IVsOutputWindow>();
44+
_statusBar = await package.GetServiceAsync<SVsStatusbar, IVsStatusbar>();
45+
_paneName = name;
46+
47+
// get VS debug pane
48+
Guid tempId = VSConstants.GUID_OutWindowDebugPane;
49+
_outputWindow.GetPane(ref tempId, out _debugPane);
50+
51+
// create nanoFramework pane
52+
tempId = s_DeploymentMessagesPaneGuid;
53+
_outputWindow.CreatePane(ref tempId, _paneName, 1, 0);
54+
_outputWindow.GetPane(ref tempId, out _nanoFrameworkMessagesPane);
55+
56+
// create firmware update manager pane
57+
tempId = s_FirmwareUpdatManagerPane;
58+
_outputWindow.CreatePane(ref tempId, ".NET nanoFramework Firmware Update Manager", 1, 0);
59+
_outputWindow.GetPane(ref tempId, out _firmwareUpdatManager);
60+
61+
// create virtual device manager pane
62+
tempId = s_VirtualDevicePane;
63+
_outputWindow.CreatePane(ref tempId, ".NET nanoFramework Virtual Device", 1, 0);
64+
_outputWindow.GetPane(ref tempId, out _virtualDevice);
65+
66+
OutputWelcomeMessage();
7667
}
7768

7869
private static void OutputWelcomeMessage()

0 commit comments

Comments
 (0)