From ca47896204482bf4a6979e3838bf7f09f61cebeb Mon Sep 17 00:00:00 2001
From: giy <giy@omp-system.ru>
Date: Fri, 02 Sep 2022 14:16:56 +0300
Subject: [PATCH] Обновление до версии 2.9.0

---
 QtVsTools.Core/WaitDialog.cs |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/QtVsTools.Core/WaitDialog.cs b/QtVsTools.Core/WaitDialog.cs
index cff8851..60a6adc 100644
--- a/QtVsTools.Core/WaitDialog.cs
+++ b/QtVsTools.Core/WaitDialog.cs
@@ -27,25 +27,21 @@
 ****************************************************************************/
 
 using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Windows.Forms;
 using Microsoft.VisualStudio;
 using Microsoft.VisualStudio.Shell;
 using Microsoft.VisualStudio.Shell.Interop;
-using Microsoft.VisualStudio.VCProjectEngine;
-using QtVsTools.VisualStudio;
 
 namespace QtVsTools.Core
 {
+    using VisualStudio;
+
     public class WaitDialog : IDisposable
     {
         static IVsThreadedWaitDialogFactory factory = null;
 
-        public IVsThreadedWaitDialog2 VsWaitDialog { get; private set; }
+        private IVsThreadedWaitDialog2 VsWaitDialog { get; set; }
 
-        public bool Running { get; private set; }
+        private bool Running { get; set; }
 
         bool? vsDialogCanceled = null;
 
@@ -53,14 +49,15 @@
         {
             get
             {
+                ThreadHelper.ThrowIfNotOnUIThread();
+
                 if (vsDialogCanceled.HasValue)
                     return vsDialogCanceled.Value;
 
                 if (VsWaitDialog == null)
                     return false;
 
-                bool canceled = false;
-                int res = VsWaitDialog.HasCanceled(out canceled);
+                int res = VsWaitDialog.HasCanceled(out bool canceled);
                 if (res != VSConstants.S_OK)
                     return false;
 
@@ -76,6 +73,8 @@
 
         static WaitDialog Create(IVsThreadedWaitDialogFactory dialogFactory)
         {
+            ThreadHelper.ThrowIfNotOnUIThread();
+
             if (factory == null) {
                 factory = dialogFactory ?? VsServiceProvider
                     .GetService<SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>();
@@ -83,8 +82,7 @@
                     return null;
             }
 
-            IVsThreadedWaitDialog2 vsWaitDialog = null;
-            factory.CreateInstance(out vsWaitDialog);
+            factory.CreateInstance(out IVsThreadedWaitDialog2 vsWaitDialog);
             if (vsWaitDialog == null)
                 return null;
 
@@ -105,6 +103,8 @@
             bool showMarqueeProgress = true,
             IVsThreadedWaitDialogFactory dialogFactory = null)
         {
+            ThreadHelper.ThrowIfNotOnUIThread();
+
             var dialog = Create(dialogFactory);
             if (dialog == null)
                 return null;
@@ -129,6 +129,8 @@
             bool isCancelable = false,
             IVsThreadedWaitDialogFactory dialogFactory = null)
         {
+            ThreadHelper.ThrowIfNotOnUIThread();
+
             var dialog = Create(dialogFactory);
             if (dialog == null)
                 return null;
@@ -151,12 +153,13 @@
             string statusBarText = null,
             bool disableCancel = false)
         {
+            ThreadHelper.ThrowIfNotOnUIThread();
+
             if (!Running)
                 return;
 
-            bool canceled = false;
             int res = VsWaitDialog.UpdateProgress(message, progressText,
-                statusBarText, currentStep, totalSteps, disableCancel, out canceled);
+                statusBarText, currentStep, totalSteps, disableCancel, out bool canceled);
 
             if (res != VSConstants.S_OK)
                 return;
@@ -167,18 +170,22 @@
 
         public void Stop()
         {
+            ThreadHelper.ThrowIfNotOnUIThread();
+
             if (!Running)
                 return;
 
             Running = false;
-            int canceled = 0;
-            VsWaitDialog.EndWaitDialog(out canceled);
+            VsWaitDialog.EndWaitDialog(out int canceled);
             Canceled = (canceled != 0);
         }
 
         void IDisposable.Dispose()
         {
-            Stop();
+            ThreadHelper.JoinableTaskFactory.Run(async () => {
+                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+                Stop();
+            });
         }
     }
 }

--
Gitblit v1.9.1