using System.Windows; namespace ShrlAlgoToolkit.RevitAddins.Assists; public sealed record SingletonViewAssist where T : Window, new() { private static T _instance; private static readonly object Padlock = new(); private SingletonViewAssist() { } public static T GetInstance(out bool isNewCreate) { isNewCreate = false; //double-check locking if (_instance == null) { isNewCreate = true; lock (Padlock) { _instance ??= new T(); _instance.Closed += OnWindowClosed; } } return _instance; } private static void OnWindowClosed(object sender, EventArgs e) { _instance = null; } }