コード例 #1
0
        private void UpdateCommandsForProjectOnDispatcher(IVsHierarchy project)
        {
            Logger.Info($"Dispatching update commands function call for project '{project.GetDisplayName()}'");

            Application.Current.Dispatcher.BeginInvoke(
                DispatcherPriority.Normal,
                new Action(() =>
            {
                // 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.

                Logger.Info($"Dispatched update commands function call for project '{project.GetDisplayName()}'");

                if (project.GetGuid() == Guid.Empty)
                {
                    Logger.Info($"Race condition might occurred while dispatching update commands function call. Project is already unloaded.");
                }

                UpdateCommandsForProject(project);
            }));
        }
コード例 #2
0
        private void UpdateCommandsForProjectOnDispatcher(IVsHierarchy project, bool onlyIfVcsSupportEnabled)
        {
            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 (onlyIfVcsSupportEnabled && !IsVcsSupportEnabled)
                {
                    return;
                }

                Logger.Info($"Dispatched update commands function call for project '{project.GetDisplayName()}'");

                if (project.GetGuid() == Guid.Empty)
                {
                    Logger.Info($"Race condition might occurred while dispatching update commands function call. Project is already unloaded.");
                }

                ToolWindowHistory.SaveState();

                UpdateCommandsForProject(project);
            });
        }