/// <summary> /// Check if window was closed through the code with Close method or from /// UI if it's from the code it's fine otherwise opponent left the game,send /// correct message to server. /// </summary> /// <param name="e"></param> protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { bool wasCodeClosed = new StackTrace().GetFrames().FirstOrDefault(x => x.GetMethod() == typeof(Window).GetMethod("Close")) != null; vm.Disconnected(); base.OnClosing(e); if (!wasCodeClosed) { // without the program doesn't really exit. Environment.Exit(0); } }
/// <summary> /// Check if window was closed through the code with Close method or from /// UI if it's from the code it's fine otherwise opponent left the game,send /// correct message to server. /// </summary> /// <param name="e"></param> protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { bool wasCodeClosed = new StackTrace().GetFrames().FirstOrDefault(x => x.GetMethod() == typeof(Window).GetMethod("Close")) != null; if (!wasCodeClosed) { // Closed some other way.Send exit. vm.Disconnected(); } base.OnClosing(e); }