private void ConnectButton_Click(object sender, RoutedEventArgs e) { Console.WriteLine("Connecting to the TCP server."); if (!ConduitClient.Connect()) { Console.WriteLine("Unable to connect to the TCP server."); return; } Console.WriteLine("Connected successfully."); ConduitClient.DataReceived += (o, ev) => { switch (ev.Packet.PacketType) { case ConduitPacketType.Print: Console.WriteLine(Encoding.Default.GetString(ev.Packet.Data)); break; case ConduitPacketType.ProcessSelect: Console.WriteLine("Process selection received."); Dispatcher.Invoke(() => { var pid = Convert.ToInt32(Encoding.Default.GetString(ev.Packet.Data)); SelectedProcess.Process = Process.GetProcessById(pid); var icon = ProcessUtility.GetProcessIcon(SelectedProcess.Process); if (icon != null) { var source = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); SelectedProcess.Icon = source; } else { Console.WriteLine("Icon could not be resolved."); } SelectedProcessIcon.Source = SelectedProcess.Icon; SelectedProcessName.Content = SelectedProcess.Process.ProcessName; }); break; } }; ScriptListBox.IsEnabled = true; ExecuteButton.IsEnabled = true; TerminateButton.IsEnabled = false; ConnectButton.IsEnabled = false; }