优化退出线程

This commit is contained in:
ZouJin 2023-11-20 23:57:54 +08:00
parent 3ad01e4782
commit 2157095823
2 changed files with 25 additions and 11 deletions

View File

@ -356,8 +356,6 @@ namespace VPet_Simulator.Core
public void Dispose() public void Dispose()
{ {
EventTimer.Stop();
MoveTimer.Enabled = false;
EventTimer.Dispose(); EventTimer.Dispose();
MoveTimer.Dispose(); MoveTimer.Dispose();
MsgBar.Dispose(); MsgBar.Dispose();

View File

@ -267,9 +267,7 @@ namespace VPet_Simulator.Windows
if (App.MainWindows.Count <= 1) if (App.MainWindows.Count <= 1)
{ {
try try
{ {
if (IsSteamUser)
SteamClient.Shutdown();//关掉和Steam的连线
if (Core != null && Core.Graph != null) if (Core != null && Core.Graph != null)
{ {
foreach (var igs in Core.Graph.GraphsList.Values) foreach (var igs in Core.Graph.GraphsList.Values)
@ -283,17 +281,18 @@ namespace VPet_Simulator.Windows
} }
} }
} }
if (Main != null) while (Windows.Count != 0)
{ {
Main.Dispose(); Windows[0].Close();
}
if (winSetting != null)
{
winSetting.Close();
} }
Main?.Dispose();
AutoSaveTimer?.Stop(); AutoSaveTimer?.Stop();
MusicTimer?.Stop(); MusicTimer?.Stop();
petHelper?.Close(); petHelper?.Close();
winSetting?.Close();
winBetterBuy?.Close();
if (IsSteamUser)
SteamClient.Shutdown();//关掉和Steam的连线
if (notifyIcon != null) if (notifyIcon != null)
{ {
notifyIcon.Visible = false; notifyIcon.Visible = false;
@ -310,10 +309,27 @@ namespace VPet_Simulator.Windows
} }
else else
{ {
if (Core != null && Core.Graph != null)
{
foreach (var igs in Core.Graph.GraphsList.Values)
{
foreach (var ig2 in igs.Values)
{
foreach (var ig3 in ig2)
{
ig3.Stop();
}
}
}
}
while (Windows.Count != 0) while (Windows.Count != 0)
{ {
Windows[0].Close(); Windows[0].Close();
} }
Main?.Dispose();
AutoSaveTimer?.Stop();
MusicTimer?.Stop();
petHelper?.Close();
winSetting?.Close(); winSetting?.Close();
winBetterBuy?.Close(); winBetterBuy?.Close();
App.MainWindows.Remove(this); App.MainWindows.Remove(this);