修复bug和新增部分功能
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Sai.Toolkit.Core.Helpers;
|
||||
public sealed record SingletonViewHelper<T>
|
||||
where T : Window, new()
|
||||
{
|
||||
private static T instance;
|
||||
private static T _instance;
|
||||
private static readonly object Padlock = new();
|
||||
|
||||
private SingletonViewHelper() { }
|
||||
@@ -15,21 +15,21 @@ public sealed record SingletonViewHelper<T>
|
||||
{
|
||||
isNewCreate = false;
|
||||
//double-check locking
|
||||
if (instance == null)
|
||||
if (_instance == null)
|
||||
{
|
||||
isNewCreate = true;
|
||||
lock (Padlock)
|
||||
{
|
||||
instance ??= new T();
|
||||
instance.Closed += OnWindowClosed;
|
||||
_instance ??= new T();
|
||||
_instance.Closed += OnWindowClosed;
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private static void OnWindowClosed(object sender, EventArgs e)
|
||||
{
|
||||
instance = null;
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user