private void FileStorage_FileStorageChanged(object sender, FileStorageChangedEventArgs e) { // This event is triggered on non-main thread! Logger.Info($"Dispatching update commands function call"); JoinableTaskFactory.RunAsync(async delegate { // git branch and merge might lead to a race condition here. // If a branch is checkout where the json file differs, the // filewatcher will trigger an event which is dispatched here. // However, while the function call is queued VS may reopen the // solution due to changes. This will ultimately result in a // null ref exception because the project object is unloaded. // UpdateCommandsForProject() will skip such projects because // their guid is empty. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (!IsVcsSupportEnabled) { return; } ToolWindowHistory.SaveState(); IEnumerable <IVsHierarchy> projects; if (e.IsSolutionWide) { Logger.Info($"Dispatched update commands function calls for the solution."); projects = vsHelper.GetSupportedProjects(); } else { Logger.Info($"Dispatched update commands function call for project '{e.Project.GetDisplayName()}'"); projects = new[] { e.Project }; } foreach (var project in projects) { if (project.GetGuid() == Guid.Empty) { Logger.Info($"Race condition might occurred while dispatching update commands function call. Project is already unloaded."); } UpdateCommandsForProject(project); } }); }
private void FileStorage_FileStorageChanged(object sender, FileStorageChangedEventArgs e) { // This event is triggered on non-main thread! UpdateCommandsForProjectOnDispatcher(e.Project, onlyIfVcsSupportEnabled: true); }