Call AdviseRunningDocTableEvents on UI thread. (#5783)

* Call AdviseRunningDocTableEvents on UI thread.

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1441597

* Actually switch to main thread....

* Add comment.
This commit is contained in:
N. Taylor Mullen 2021-11-24 17:44:28 -08:00 коммит произвёл GitHub
Родитель f7be11bb79
Коммит 1f785f416c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Workspaces.Extensions;
using Microsoft.VisualStudio.Shell.Interop;
@ -52,8 +53,14 @@ namespace Microsoft.VisualStudio.Editor.Razor.Documents
_runningDocumentTable = (IVsRunningDocumentTable4)runningDocumentTable;
_editorAdaptersFactory = editorAdaptersFactory;
var hr = runningDocumentTable.AdviseRunningDocTableEvents(new RunningDocumentTableEventSink(this), out _);
Marshal.ThrowExceptionForHR(hr);
// Need to grab running doc-table events but that requires the UI thread.
joinableTaskContext.Factory.Run(async () =>
{
await joinableTaskContext.Factory.SwitchToMainThreadAsync();
var hr = runningDocumentTable.AdviseRunningDocTableEvents(new RunningDocumentTableEventSink(this), out _);
Marshal.ThrowExceptionForHR(hr);
});
_documentsByCookie = new Dictionary<uint, List<DocumentKey>>();
_cookiesByDocument = new Dictionary<DocumentKey, uint>();