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

@@ -284,9 +284,8 @@ public sealed class ScreenSmokeTests
}
/// <summary>
/// The STA dispatcher of the process-wide WPF <see cref="Application"/> (only one may exist per process): reuses the
/// one an earlier WPF test created, otherwise starts it with the Titano theme; then merges the client's styles and
/// section templates, as <c>App.xaml</c> does.
/// The dispatcher of the shared WPF <see cref="Application"/> with the client's styles and section templates merged,
/// as <c>App.xaml</c> does.
/// </summary>
internal static class ScreenHost
{
@@ -296,28 +295,10 @@ internal static class ScreenHost
private static Dispatcher Start()
{
var app = Application.Current;
Dispatcher? dispatcher = app?.Dispatcher;
if (dispatcher is null)
var dispatcher = WpfApplication.Dispatcher;
dispatcher.Invoke(() =>
{
using var ready = new ManualResetEventSlim();
var thread = new Thread(() =>
{
var created = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
ThemeManager.Initialize(created, 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();
}
dispatcher!.Invoke(() =>
{
// pack:// URIs parse only once an Application exists (it registers the scheme), so this one is built here,
// not in a static field: the first WPF test of a run may be the one that starts the Application.
// pack:// URIs parse only once an Application exists (it registers the scheme), so this one is built here.
var sectionTemplates = new Uri("pack://application:,,,/Titano;component/Shell/SectionTemplates.xaml", UriKind.Absolute);
var current = Application.Current;
AppResources.Merge(current);