33 lines
753 B
C#
33 lines
753 B
C#
using System.Windows;
|
|
|
|
namespace ShrlAlgoToolkit.Core.Assists;
|
|
|
|
public sealed record SingletonViewAssist<T>
|
|
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;
|
|
}
|
|
} |