Removed unnecessary ThreadStart

This commit is contained in:
MaxXor 2015-03-18 18:58:17 +01:00
parent 90a4d4a89f
commit 5855fc9adf
2 changed files with 39 additions and 37 deletions

View File

@ -21,7 +21,7 @@ public static void HandleInitialize(Client client, Initialize packet, FrmMain ma
mainForm.ListenServer.AllTimeConnectedClients++; mainForm.ListenServer.AllTimeConnectedClients++;
mainForm.UpdateWindowTitle(mainForm.ListenServer.ConnectedClients, mainForm.lstClients.SelectedItems.Count); mainForm.UpdateWindowTitle(mainForm.ListenServer.ConnectedClients, mainForm.lstClients.SelectedItems.Count);
new Thread(new ThreadStart(() => new Thread(() =>
{ {
try try
{ {
@ -52,7 +52,7 @@ public static void HandleInitialize(Client client, Initialize packet, FrmMain ma
} }
catch catch
{ } { }
})).Start(); }).Start();
} }
private static void ShowPopup(Client c, FrmMain mainForm) private static void ShowPopup(Client c, FrmMain mainForm)
@ -62,7 +62,7 @@ private static void ShowPopup(Client c, FrmMain mainForm)
public static void HandleStatus(Client client, Status packet, FrmMain mainForm) public static void HandleStatus(Client client, Status packet, FrmMain mainForm)
{ {
new Thread(new ThreadStart(() => new Thread(() =>
{ {
foreach (ListViewItem lvi in mainForm.lstClients.Items) foreach (ListViewItem lvi in mainForm.lstClients.Items)
{ {
@ -77,12 +77,12 @@ public static void HandleStatus(Client client, Status packet, FrmMain mainForm)
} }
} }
})).Start(); }).Start();
} }
public static void HandleUserStatus(Client client, UserStatus packet, FrmMain mainForm) public static void HandleUserStatus(Client client, UserStatus packet, FrmMain mainForm)
{ {
new Thread(new ThreadStart(() => new Thread(() =>
{ {
foreach (ListViewItem lvi in mainForm.lstClients.Items) foreach (ListViewItem lvi in mainForm.lstClients.Items)
{ {
@ -97,7 +97,7 @@ public static void HandleUserStatus(Client client, UserStatus packet, FrmMain ma
} }
} }
})).Start(); }).Start();
} }
public static void HandleRemoteDesktopResponse(Client client, DesktopResponse packet) public static void HandleRemoteDesktopResponse(Client client, DesktopResponse packet)
@ -105,35 +105,35 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa
if (client.Value.FrmRdp == null) if (client.Value.FrmRdp == null)
return; return;
// we can not dispose all bitmaps here, cause they are later used again in `client.Value.LastDesktop`
if (client.Value.LastDesktop == null) if (client.Value.LastDesktop == null)
{ {
using (Bitmap newScreen = (Bitmap)Helper.Helper.CByteToImg(packet.Image)) Bitmap newScreen = (Bitmap)Helper.Helper.CByteToImg(packet.Image);
client.Value.LastDesktop = newScreen;
client.Value.FrmRdp.Invoke((MethodInvoker)delegate
{ {
client.Value.LastDesktop = newScreen; client.Value.FrmRdp.picDesktop.Image = newScreen;
client.Value.FrmRdp.Invoke((MethodInvoker)delegate });
{ newScreen = null;
client.Value.FrmRdp.picDesktop.Image = newScreen;
});
}
} }
else else
{ {
using (Bitmap screen = (Bitmap)Helper.Helper.CByteToImg(packet.Image)) using (Bitmap screen = (Bitmap) Helper.Helper.CByteToImg(packet.Image))
{ {
using (Bitmap newScreen = new Bitmap(screen.Width, screen.Height)) Bitmap newScreen = new Bitmap(screen.Width, screen.Height);
{
using (Graphics g = Graphics.FromImage(newScreen))
{
g.DrawImage(client.Value.LastDesktop, 0, 0, newScreen.Width, newScreen.Height);
g.DrawImage(screen, 0, 0, newScreen.Width, newScreen.Height);
}
client.Value.LastDesktop = newScreen; using (Graphics g = Graphics.FromImage(newScreen))
client.Value.FrmRdp.Invoke((MethodInvoker)delegate {
{ g.DrawImage(client.Value.LastDesktop, 0, 0, newScreen.Width, newScreen.Height);
client.Value.FrmRdp.picDesktop.Image = newScreen; g.DrawImage(screen, 0, 0, newScreen.Width, newScreen.Height);
});
} }
client.Value.LastDesktop = newScreen;
client.Value.FrmRdp.Invoke((MethodInvoker) delegate
{
client.Value.FrmRdp.picDesktop.Image = newScreen;
});
newScreen = null;
} }
} }
@ -151,7 +151,7 @@ public static void HandleGetProcessesResponse(Client client, GetProcessesRespons
client.Value.FrmTm.lstTasks.Items.Clear(); client.Value.FrmTm.lstTasks.Items.Clear();
}); });
new Thread(new ThreadStart(() => new Thread(() =>
{ {
for (int i = 0; i < packet.Processes.Length; i++) for (int i = 0; i < packet.Processes.Length; i++)
{ {
@ -169,7 +169,7 @@ public static void HandleGetProcessesResponse(Client client, GetProcessesRespons
{ break; } { break; }
} }
} }
})).Start(); }).Start();
} }
public static void HandleDrivesResponse(Client client, DrivesResponse packet) public static void HandleDrivesResponse(Client client, DrivesResponse packet)
@ -195,7 +195,7 @@ public static void HandleDirectoryResponse(Client client, DirectoryResponse pack
client.Value.FrmFm.lstDirectory.Items.Clear(); client.Value.FrmFm.lstDirectory.Items.Clear();
}); });
new Thread(new ThreadStart(() => new Thread(() =>
{ {
ListViewItem lviBack = new ListViewItem(new string[] { "..", "", "Directory" }); ListViewItem lviBack = new ListViewItem(new string[] { "..", "", "Directory" });
lviBack.Tag = "dir"; lviBack.Tag = "dir";
@ -254,7 +254,7 @@ public static void HandleDirectoryResponse(Client client, DirectoryResponse pack
} }
client.Value.LastDirectorySeen = true; client.Value.LastDirectorySeen = true;
})).Start(); }).Start();
} }
public static void HandleDownloadFileResponse(Client client, DownloadFileResponse packet) public static void HandleDownloadFileResponse(Client client, DownloadFileResponse packet)
@ -290,7 +290,7 @@ public static void HandleDownloadFileResponse(Client client, DownloadFileRespons
if (Continue) if (Continue)
{ {
new Thread(new ThreadStart(() => new Thread(() =>
{ {
try try
{ {
@ -311,7 +311,7 @@ public static void HandleDownloadFileResponse(Client client, DownloadFileRespons
} }
catch catch
{ } { }
})).Start(); }).Start();
} }
else else
{ {

View File

@ -106,7 +106,7 @@ private void ctxtDownload_Click(object sender, EventArgs e)
{ {
if (lstDirectory.SelectedItems.Count != 0) if (lstDirectory.SelectedItems.Count != 0)
{ {
new Thread(new ThreadStart(() => new Thread(() =>
{ {
foreach (ListViewItem files in lstDirectory.SelectedItems) foreach (ListViewItem files in lstDirectory.SelectedItems)
{ {
@ -122,9 +122,11 @@ private void ctxtDownload_Click(object sender, EventArgs e)
new Core.Packets.ServerPackets.DownloadFile(path, ID).Execute(_connectClient); new Core.Packets.ServerPackets.DownloadFile(path, ID).Execute(_connectClient);
ListViewItem lvi = new ListViewItem(new string[] { ID.ToString(), "Downloading...", files.SubItems[0].Text }); ListViewItem lvi =
new ListViewItem(new string[]
this.Invoke((MethodInvoker)delegate {ID.ToString(), "Downloading...", files.SubItems[0].Text});
this.Invoke((MethodInvoker) delegate
{ {
lstTransfers.Items.Add(lvi); lstTransfers.Items.Add(lvi);
}); });
@ -132,7 +134,7 @@ private void ctxtDownload_Click(object sender, EventArgs e)
Thread.Sleep(50); Thread.Sleep(50);
} }
} }
})).Start(); }).Start();
} }
} }
} }