bool CloseStethoscope(string stethoscopeName) { var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName); if (stethoscopes.Count() == 0) { return(false); } var stethoscope = stethoscopes.First(); var formProcessBar = new FrmProcessBar(false, string.Format("正在断设备 {0} 连接!", stethoscopeName)) { CancelBtnVisible = false }; Thread pairThread = new Thread(() => { //var _stethoscope = obj as Stethoscope; try { if (stethoscope.IsConnected) { stethoscope.Disconnected += (s, arg) => { Invoke(new MethodInvoker(() => { formProcessBar.Close(); })); }; stethoscope.Disconnect(); Mediator.ShowMsg(string.Format("听诊器{0}断开成功", stethoscope.Name)); } } catch (Exception ex) { Mediator.ShowMsg(string.Format("听诊器{0}断开失败", stethoscope.Name)); //好像从来没有进来过 } finally { Invoke(new MethodInvoker(delegate() { formProcessBar.Close(); })); } }); pairThread.Start(); formProcessBar.ShowDialog(); return(stethoscope.IsConnected); }
bool OpenStethoscope(string stethoscopeName) { var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName); if (!stethoscopes.Any()) { return(false); } var stethoscope = stethoscopes.First(); var formProcessBar = new FrmProcessBar(false, string.Format("正在开启设备{0}连接!", stethoscopeName)) { CancelBtnVisible = false };; Thread pairThread = new Thread(() => { try { if (!stethoscope.IsConnected) { stethoscope.Connect(); ShowMsg(string.Format("听诊器 {0} 连接成功...", stethoscopeName), false); if (OnSetehoscopeConnect != null) { OnSetehoscopeConnect(); } Current = stethoscope; //Mediator.ShowMsg(string.Format("听诊器{0}连接成功", stethoscope.Name)); } } catch (Exception ex) { ShowMsg(string.Format("听诊器 {0} 连接失败...", stethoscopeName)); } finally { Invoke(new MethodInvoker(() => { formProcessBar.Close(); })); } }); pairThread.Start(); formProcessBar.ShowDialog(); return(stethoscope.IsConnected); }
bool OpenStethoscope(string stethoscopeName) { var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName); if (stethoscopes.Count() == 0) { return(false); } var stethoscope = stethoscopes.First(); var formProcessBar = new FrmProcessBar(false, string.Format("正在开启设备{0}连接!", stethoscopeName)) { CancelBtnVisible = false };; Thread pairThread = new Thread(() => { //var _stethoscope = obj as Stethoscope; try { if (!stethoscope.IsConnected) { stethoscope.Connect(); Mediator.ShowMsg(string.Format("听诊器{0}连接成功", stethoscope.Name)); } } catch (Exception ex) { Mediator.ShowMsg(string.Format("听诊器{0}连接失败", stethoscope.Name)); //MessageBox.Show("听诊器连接失败,请确认听诊器是否开启了蓝牙连接状态!"); Mediator.ShowMsg("听诊器连接失败,请确认听诊器是否开启了蓝牙连接状态!"); } finally { Invoke(new MethodInvoker(delegate() { formProcessBar.Close(); })); } }); pairThread.Start(); formProcessBar.ShowDialog(); return(stethoscope.IsConnected); }
bool CloseStethoscope(string stethoscopeName) { var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName); if (!stethoscopes.Any()) { return(false); } var stethoscope = stethoscopes.First(); var formProcessBar = new FrmProcessBar(false, string.Format("正在断设备 {0} 连接!", stethoscopeName)) { CancelBtnVisible = false }; Thread pairThread = new Thread(() => { try { if (stethoscope.IsConnected) { stethoscope.Disconnect(); ShowMsg(string.Format("听诊器 {0} 断开连接...", stethoscopeName), false); } } catch (Exception ex) { //好像从来没有进来过 } finally { Invoke(new MethodInvoker(() => { formProcessBar.Close(); })); } }); pairThread.Start(); formProcessBar.ShowDialog(); return(stethoscope.IsConnected); }