private void SetMainText(object sender, STEP_LEVEL _level) { if (_level == STEP_LEVEL.FAIL || _level == STEP_LEVEL.PASS || _level == STEP_LEVEL.BIND_TIMEOUT) { bTaskRunning = false; } if (UpdateWorkStatusHandler != null) { StepArgs mArgs = new StepArgs(); mArgs.level = _level; UpdateWorkStatusHandler(sender, mArgs); } }
private void SetMainText(STEP_LEVEL level) { if (this.label_MainResult.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True { while (!this.label_MainResult.IsHandleCreated) { //解决窗体关闭时出现“访问已释放句柄“的异常 if (this.label_MainResult.Disposing || this.label_MainResult.IsDisposed) { return; } } SetMainTextCallback d = new SetMainTextCallback(SetMainText); this.label_MainResult.Invoke(d, new object[] { level }); } else { switch (level) { case STEP_LEVEL.NONE: this.panel_MainResult.BackColor = Color.LightBlue; this.label_MainTip.Text = "扫描设备,进行测试"; this.label_MainResult.Text = "开 始 测 试"; break; case STEP_LEVEL.WAIT_POWER: this.panel_MainResult.BackColor = Color.Yellow; this.label_MainResult.Text = "等待设备上电..."; this.label_MainTip.Text = ""; break; case STEP_LEVEL.PASS: this.TestTimeTicker.Enabled = false; this.panel_MainResult.BackColor = Color.Green; this.label_MainResult.Text = String.Format("{0}\n成 功", mPhoneTask.mSN); this.label_MainTip.Text = "再次扫描,进行下一次测试!"; this.textBox_SN.Enabled = true; this.textBox_SN.Text = ""; this.textBox_SN.Focus(); break; case STEP_LEVEL.CHECK_SN: this.panel_MainResult.BackColor = Color.Yellow; this.label_MainResult.Text = "SN号检查..."; this.label_MainTip.Text = ""; break; case STEP_LEVEL.BIND_KEY1: this.panel_MainResult.BackColor = Color.Yellow; this.label_MainResult.Text = "5秒内,多次按键\n绑定第一把钥匙..."; this.label_MainTip.Text = ""; break; case STEP_LEVEL.BIND_KEY2: this.panel_MainResult.BackColor = Color.Yellow; this.label_MainResult.Text = "5秒内,多次按键\n绑定第二把钥匙..."; this.label_MainTip.Text = ""; break; case STEP_LEVEL.FAIL: this.TestTimeTicker.Enabled = false; this.panel_MainResult.BackColor = Color.Red; this.label_MainResult.Text = String.Format("{0}\n失 败", mPhoneTask.mSN); this.label_MainTip.Text = "再次扫描,进行下一次测试!"; this.textBox_SN.Enabled = true; this.textBox_SN.Text = ""; this.textBox_SN.Focus(); break; case STEP_LEVEL.BIND_TIMEOUT: this.TestTimeTicker.Enabled = false; this.panel_MainResult.BackColor = Color.Red; this.label_MainResult.Text = String.Format("{0}\n绑 定 超 时", mPhoneTask.mSN); this.label_MainTip.Text = "再次扫描,进行下一次测试!"; this.textBox_SN.Enabled = true; this.textBox_SN.Text = ""; this.textBox_SN.Focus(); break; } } }