From b0bf31b29c078425f526c2e90feb1ac58da2cc5f Mon Sep 17 00:00:00 2001 From: Camilo Alvarez Date: Thu, 7 Feb 2019 17:39:40 -0500 Subject: [PATCH] Remove deadlock in #1247 #1247 was caused by a loop of the putty control calling the tab dispose and back again. Created a flag to indicate the ConnectionTab that the closing process was called by the protocol and not the user. --- mRemoteV1/Connection/Protocol/PuttyBase.cs | 7 ++-- mRemoteV1/UI/Tabs/ConnectionTab.cs | 40 ++++++++++++++-------- mRemoteV1/UI/Window/ConnectionWindow.cs | 2 +- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/mRemoteV1/Connection/Protocol/PuttyBase.cs b/mRemoteV1/Connection/Protocol/PuttyBase.cs index 039e4ea7c..c40a0b069 100644 --- a/mRemoteV1/Connection/Protocol/PuttyBase.cs +++ b/mRemoteV1/Connection/Protocol/PuttyBase.cs @@ -236,11 +236,8 @@ namespace mRemoteNG.Connection.Protocol try { - Console.WriteLine(@"Skipping Dispose for now!"); - PuttyProcess.Close(); - // TODO: Figure out why this hangs... - //PuttyProcess.Dispose(); - Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strPuttyDisposeFailed + Environment.NewLine + @"SKIPPING DISPOSE - CAUSES HANG IN THIS BUILD!!!", true); + PuttyProcess.Close(); + PuttyProcess.Dispose(); } catch (Exception ex) { diff --git a/mRemoteV1/UI/Tabs/ConnectionTab.cs b/mRemoteV1/UI/Tabs/ConnectionTab.cs index b47e913ad..0f1378593 100644 --- a/mRemoteV1/UI/Tabs/ConnectionTab.cs +++ b/mRemoteV1/UI/Tabs/ConnectionTab.cs @@ -13,11 +13,18 @@ namespace mRemoteNG.UI.Tabs { public partial class ConnectionTab : DockContent { + /// + ///Silent close ignores the popup asking for confirmation + /// public bool silentClose { get; set; } + /// + /// Protocol close ignores the interface controller cleanup and the user confirmation dialog + /// + public bool protocolClose { get; set; } public ConnectionTab() { - InitializeComponent(); + InitializeComponent(); GotFocus += ConnectionTab_GotFocus; } @@ -28,34 +35,37 @@ namespace mRemoteNG.UI.Tabs protected override void OnFormClosing(FormClosingEventArgs e) { - if(!silentClose) + if(!protocolClose) { - if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All) + if (!silentClose) { - var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, string.Format(Language.strConfirmCloseConnectionPanelMainInstruction, TabText), "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question); - if (CTaskDialog.VerificationChecked) + if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All) { - Settings.Default.ConfirmCloseConnection--; - } - if (result == DialogResult.No) - { - e.Cancel = true; + var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, string.Format(Language.strConfirmCloseConnectionPanelMainInstruction, TabText), "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question); + if (CTaskDialog.VerificationChecked) + { + Settings.Default.ConfirmCloseConnection--; + } + if (result == DialogResult.No) + { + e.Cancel = true; + } + else + { + ((InterfaceControl)Tag)?.Protocol.Close(); + } } else { + // close without the confirmation prompt... ((InterfaceControl)Tag)?.Protocol.Close(); } } else { - // close without the confirmation prompt... ((InterfaceControl)Tag)?.Protocol.Close(); } } - else - { - ((InterfaceControl)Tag)?.Protocol.Close(); - } base.OnFormClosing(e); } diff --git a/mRemoteV1/UI/Window/ConnectionWindow.cs b/mRemoteV1/UI/Window/ConnectionWindow.cs index e373e53e4..1a19f6aa4 100644 --- a/mRemoteV1/UI/Window/ConnectionWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionWindow.cs @@ -741,7 +741,7 @@ namespace mRemoteNG.UI.Window var protocolBase = sender as ProtocolBase; if (!(protocolBase?.InterfaceControl.Parent is ConnectionTab tabPage)) return; if (tabPage.Disposing) return; - tabPage.silentClose = true; + tabPage.protocolClose = true; Invoke(new Action(() => tabPage.Close())); }