增强窗口关闭处理和资源清理
在 `LoginWindow.xaml` 中添加了 `Closing` 事件处理程序,以便在窗口关闭时执行特定逻辑。新增的 `Window_Closing` 方法会检查 `MainWindow.token` 是否为 `null`,并在必要时关闭应用程序。此外,在 `MainWindow.xaml.cs` 中确保在清理资源时将 `token` 设置为 `null`,以避免潜在的资源泄漏或错误。
This commit is contained in:
parent
424311f088
commit
15147b88a6
@ -8,7 +8,7 @@
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" x:Class="chatclient.LoginWindow"
|
||||
mc:Ignorable="d"
|
||||
Title="LoginWindow" Height="590" Width="360" MinHeight="590" MinWidth="360" MaxHeight="590" MaxWidth="360"
|
||||
ResizeMode="NoResize">
|
||||
ResizeMode="NoResize" Closing="Window_Closing">
|
||||
|
||||
<TabControl>
|
||||
<TabItem Header="登录账号" Cursor="Hand" Height="40">
|
||||
|
@ -213,6 +213,10 @@ namespace chatclient
|
||||
// 例如:UserName = LoadSavedUsername();
|
||||
// Update("UserName");
|
||||
}
|
||||
public void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
if(MainWindow.token == null) Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,6 +339,7 @@ namespace chatclient
|
||||
Client?.Shutdown(SocketShutdown.Both);
|
||||
Client?.Close();
|
||||
Client?.Dispose();
|
||||
token = null;
|
||||
_trayManager?.Dispose();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user