diff options
author | Miguel Costa <miguel.costa@qt.io> | 2022-02-10 13:53:26 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2022-02-11 11:47:34 +0000 |
commit | a2dec3c1e91c8586127c1ddf19568b34791d9048 (patch) | |
tree | 7adac3aa2bcd4ca008fa9fc576f06461217bf329 | |
parent | 3c16ccccb46f978d94540400ad715fd2a1d4df35 (diff) |
Fix test server warnings
Change-Id: I22c0a8537737b5fdc8ec756b5bcf8145b052ad48
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | QtVsTest/Macro.cs | 16 | ||||
-rw-r--r-- | QtVsTest/MacroServer.cs | 4 |
2 files changed, 7 insertions, 13 deletions
diff --git a/QtVsTest/Macro.cs b/QtVsTest/Macro.cs index 497359b5..64281af0 100644 --- a/QtVsTest/Macro.cs +++ b/QtVsTest/Macro.cs @@ -106,6 +106,7 @@ namespace QtVsTest.Macros AsyncPackage Package { get; } EnvDTE80.DTE2 Dte { get; } + IntPtr MainWindowHWnd { get; } AutomationElement UiRoot => AutomationElement.RootElement; @@ -114,13 +115,8 @@ namespace QtVsTest.Macros { get { - ThreadHelper.ThrowIfNotOnUIThread(); if (_UiVsRoot == null) -#if VS2022 - _UiVsRoot = AutomationElement.FromHandle(Dte.MainWindow.HWnd); -#else - _UiVsRoot = AutomationElement.FromHandle(new IntPtr(Dte.MainWindow.HWnd)); -#endif + _UiVsRoot = AutomationElement.FromHandle(MainWindowHWnd); return _UiVsRoot; } } @@ -195,6 +191,7 @@ namespace QtVsTest.Macros public Macro( AsyncPackage package, EnvDTE80.DTE2 dte, + IntPtr mainWindowHWnd, JoinableTaskFactory joinableTaskFactory, CancellationToken serverLoop) { @@ -202,6 +199,7 @@ namespace QtVsTest.Macros JoinableTaskFactory = joinableTaskFactory; ServerLoop = serverLoop; Dte = dte; + MainWindowHWnd = mainWindowHWnd; ErrorMsg("Uninitialized"); } @@ -283,8 +281,6 @@ namespace QtVsTest.Macros /// <returns></returns> bool CompileMacro() { - ThreadHelper.ThrowIfNotOnUIThread(); - if (UiVsRoot == null) return ErrorMsg("UI Automation not available"); @@ -558,8 +554,6 @@ namespace QtVsTest.Macros bool InitializeUiGlobals() { - ThreadHelper.ThrowIfNotOnUIThread(); - if (MacroClass == null) return false; @@ -830,8 +824,6 @@ namespace QtVsTest.Macros MacroClass.GetField("WaitExpr", PUBLIC_STATIC) .SetValue(null, new Func<int, Func<object>, Task>(WaitExprAsync)); - ThreadHelper.ThrowIfNotOnUIThread(); - if (!InitializeUiGlobals()) return false; diff --git a/QtVsTest/MacroServer.cs b/QtVsTest/MacroServer.cs index 2014fb4c..bab0f2b5 100644 --- a/QtVsTest/MacroServer.cs +++ b/QtVsTest/MacroServer.cs @@ -70,6 +70,7 @@ namespace QtVsTest.Macros { await JoinableTaskFactory.SwitchToMainThreadAsync(Loop.Token); var DTE = await Package.GetServiceAsync(typeof(DTE)) as DTE2; + var mainWindowHWnd = new IntPtr((long)DTE.MainWindow.HWnd); await TaskScheduler.Default; var pipeName = string.Format("QtVSTest_{0}", Process.GetCurrentProcess().Id); @@ -97,7 +98,8 @@ namespace QtVsTest.Macros if (Loop.Token.IsCancellationRequested) break; - var macro = new Macro(Package, DTE, JoinableTaskFactory, Loop.Token); + var macro = new Macro( + Package, DTE, mainWindowHWnd, JoinableTaskFactory, Loop.Token); await macro.CompileAsync(Encoding.UTF8.GetString(data)); if (macro.AutoRun) await macro.RunAsync(); |