From ad660fb598b7f364aa26dfdc3f3aedc2542cb0e0 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Mon, 1 Mar 2021 17:08:42 +0800
Subject: [PATCH] lazy initialization MainForm
---
Netch/Global.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Netch/Global.cs b/Netch/Global.cs
index 6cee91ed..c415d1a8 100644
--- a/Netch/Global.cs
+++ b/Netch/Global.cs
@@ -32,7 +32,7 @@ namespace Netch
///
/// 主窗体的静态实例
///
- private static MainForm? _mainForm;
+ private static Lazy _mainForm = new(() => new MainForm());
public static readonly Mutex Mutex = new(false, "Global\\Netch");
@@ -115,7 +115,7 @@ namespace Netch
///
/// 主窗体的静态实例
///
- public static MainForm MainForm => _mainForm ??= new MainForm();
+ public static MainForm MainForm => _mainForm.Value;
public static JsonSerializerOptions NewDefaultJsonSerializerOptions => new()
{