private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (select_dialog == null) { select_dialog = new PortalSelect(tiaThread); } if (select_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TiaPortalProcess proc = select_dialog.selectedProcess(); if (proc != null) { WaitConnect wait = new WaitConnect(); wait.Show(); Application.DoEvents(); try { tiaPortal = (TiaPortal)tiaThread.RunSync((_) => { return(proc.Attach()); }, null); connectToolStripMenuItem.Enabled = false; btn_connect.Enabled = false; disconnectToolStripMenuItem.Enabled = true; btn_disconnect.Enabled = true; PortalConnected(); } catch (EngineeringException ex) { MessageBox.Show("Failed to connect to TIAPortal: " + ex.Message); } wait.Hide(); wait.Dispose(); } } }
private void PortalSelect_Load(object sender, EventArgs e) { listBox1.Items.Clear(); List <ProcItem> items = new List <ProcItem>(); tiaThread.RunSync((_) => { foreach (TiaPortalProcess proc in TiaPortal.GetProcesses()) { FileInfo proj = proc.ProjectPath; string path = null; if (proj != null) { path = proj.Name; } if (path == null) { path = "No project loaded"; } ProcItem item = new ProcItem(proc, path); items.Add(item); } return(null); }, null); foreach (ProcItem item in items) { listBox1.Items.Add(item); listBox1.SetSelected(0, true); } connectBtn.Enabled = (listBox1.SelectedItem != null); }