private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (select_dialog == null) { select_dialog = new PortalSelect(); } 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 = proc.Attach(); connectToolStripMenuItem.Enabled = false; disconnectToolStripMenuItem.Enabled = true; } catch (EngineeringException ex) { MessageBox.Show("Failed to connect to TIAPortal: " + ex.Message); } wait.Hide(); wait.Dispose(); } } }