test(app): one shared WPF Application host for every WPF test

The Server screen tests now run first and created the process's Application
through ScreenHost; the visuals tests then tried to create a second one and the
process aborted. Both hosts now use the same lazily started Application.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:55:15 +00:00
1 parent b6533b4c1c
commit 93e47c2dee
3 files changed
+42 -47

No files matched your search

@@ -294,12 +294,10 @@ public sealed class VisualsSmokeTests
}
}
/// <summary>One STA dispatcher with an Application and the Titano theme, shared by the WPF tests.</summary>
/// <summary>Runs on the dispatcher of the shared WPF <see cref="Application"/>.</summary>
private static class WpfHost
{
private static readonly Lazy<Dispatcher> Dispatcher = new(Start);
public static void Run(Action action) => Dispatcher.Value.Invoke(action);
public static void Run(Action action) => Windows.WpfApplication.Dispatcher.Invoke(action);
/// <summary>Processes queued dispatcher work (async continuations) on the current dispatcher.</summary>
public static void DoEvents()
@@ -308,24 +306,5 @@ public sealed class VisualsSmokeTests
System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, () => frame.Continue = false);
System.Windows.Threading.Dispatcher.PushFrame(frame);
}
private static Dispatcher Start()
{
Dispatcher? dispatcher = null;
using var ready = new ManualResetEventSlim();
var thread = new Thread(() =>
{
var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
ThemeManager.Initialize(app, AppTheme.Dark);
dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
ready.Set();
System.Windows.Threading.Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
ready.Wait();
return dispatcher!;
}
}
}