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
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System.Windows;
|
|
using System.Windows.Threading;
|
|
using Titano.Ui.Theming;
|
|
|
|
namespace Titano.App.Tests.Windows;
|
|
|
|
/// <summary>
|
|
/// The process-wide WPF <see cref="Application"/> (only one may ever exist per process) on its own STA thread with
|
|
/// the Titano theme. Every WPF test reaches it through here, whichever test happens to run first.
|
|
/// </summary>
|
|
internal static class WpfApplication
|
|
{
|
|
private static readonly Lazy<Dispatcher> Instance = new(Start, LazyThreadSafetyMode.ExecutionAndPublication);
|
|
|
|
public static Dispatcher Dispatcher => Instance.Value;
|
|
|
|
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!;
|
|
}
|
|
}
|