FrmMain instance null check

Added FrmMain instance null check to safely exit a thread in the
FrmKeylogger form in the case of client-server disconnection.  The
FrmKeylogger spawns a thread that waits for the enabled button to be set
to true, after successfully receiving all the log files from the client.
If the server were to somehow not process the button being enabled it
would hang in the while loop leaving the entire process to be left in
memory due to the thread being open.
This commit is contained in:
d3agle 2015-04-23 12:50:02 -05:00
parent f1942aa253
commit 53e2096deb
2 changed files with 8 additions and 4 deletions

View File

@ -79,6 +79,9 @@ namespace xServer.Forms
{
while (!btnGetLogs.Enabled)
{
if (FrmMain.Instance == null) //Provide an escape from thread in the case of client-server disconnection, a possibly rare occurence
return;
Thread.Sleep(15);
}
@ -89,13 +92,13 @@ namespace xServer.Forms
if (iFiles.Length == 0)
return;
foreach (FileInfo file in iFiles)
lstLogs.Invoke((MethodInvoker)delegate
{
lstLogs.Invoke((MethodInvoker)delegate
foreach (FileInfo file in iFiles)
{
lstLogs.Items.Add(new ListViewItem().Text = file.Name);
});
}
}
});
}).Start();
}

View File

@ -169,6 +169,7 @@ namespace xServer.Forms
UPnP.RemovePort(ushort.Parse(XMLSettings.ListenPort.ToString()));
nIcon.Visible = false;
FrmMain.Instance = null;
}
private void lstClients_SelectedIndexChanged(object sender, EventArgs e)