using System.Windows; using System.Windows.Threading; using Titano.Ui.Theming; namespace Titano.App.Tests.Windows; /// /// The process-wide WPF (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. /// internal static class WpfApplication { private static readonly Lazy 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!; } }