private void AddDeviceForm() { if (InvokeRequired) { try { Invoke((Delegate) new AddDeviceFormDelegate(AddDeviceForm)); } catch { } } else { m_mutex.WaitOne(); DeviceForm deviceForm = new DeviceForm(); if (deviceForm == null) { return; } deviceForm.BDAddressNotify += new EventHandler(DeviceBDAddressNotify); deviceForm.ConnectionNotify += new EventHandler(DeviceConnectionNotify); deviceForm.DisconnectionNotify += new EventHandler(DeviceDisconnectionNotify); deviceForm.ChangeActiveRoot += new EventHandler(DeviceChangeActiveRoot); deviceForm.CloseActiveDevice += new EventHandler(DeviceCloseActiveDevice); if (deviceForm.DeviceFormInit()) { deviceForm.TopLevel = false; deviceForm.Parent = plDevice; deviceForm.Dock = DockStyle.Fill; foreach (Control control in plDevice.Controls) { if (control.GetType().BaseType == typeof(Form)) { Form form = (Form)control; if (form.Visible) { form.Hide(); break; } } } deviceForm.Show(); AddToTreeDeviceInfo(deviceForm.devInfo, deviceForm); comPortTreeForm.ClearSelectedNode(); deviceForm.SendGAPDeviceInit(); } else { deviceForm.DeviceFormClose(false); } m_mutex.ReleaseMutex(); } }