private void connectbutton_Click(object sender, EventArgs e) { if (connected) { MessageBox.Show("Already opened a device!", "Error"); return; } if (devicecombobox.SelectedItem == null) { MessageBox.Show("No device selected!", "Error"); return; } connected_device = devicecombobox.SelectedItem as CHDKPTPDevice; LogLine("opening device: " + connected_device.Name); try { session = new Session(connected_device); session.Connect(); } catch (Exception ex) { LogLine("exception: " + ex.Message + Environment.NewLine + ex.StackTrace.ToString()); connected = false; connected_device = null; session = null; MessageBox.Show("could not open PTP session: " + ex.Message + "\n\n" + ex.StackTrace.ToString()); return; } LogLine("connected."); connected = true; statuslabel.Text = "Connected to: " + connected_device.ToString(); }