From 8a3ab64a65da226636743be07c4bee63f50da25d Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期六, 06 三月 2021 11:35:20 +0800 Subject: [PATCH] 1. 解决软件异常崩溃问题 --- src/Bro.UI.Config/MenuForms/FrmOperation.cs | 109 +++++++++++++++--------------------------------------- 1 files changed, 31 insertions(+), 78 deletions(-) diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.cs b/src/Bro.UI.Config/MenuForms/FrmOperation.cs index 891d678..43152d5 100644 --- a/src/Bro.UI.Config/MenuForms/FrmOperation.cs +++ b/src/Bro.UI.Config/MenuForms/FrmOperation.cs @@ -27,17 +27,6 @@ LoadProcessCode(); LoadProductionCode(); - - Task.Run(() => - { - Thread.Sleep(1000); - - if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad) - { - LoadProcess(); - _isFirstLoad = false; - } - }); } #region Load Codes @@ -66,7 +55,7 @@ pCodes = systemProcessCodes; } - if (pCodes.Count == 1 && pCodes[0] == "") + if (pCodes.Count == 1) { plProcess.Visible = false; _processCode = pCodes[0]; @@ -74,12 +63,21 @@ } else { - pCodes.Remove(""); + pCodes.RemoveAll(p => string.IsNullOrWhiteSpace(p)); } if (pCodes.Count > 1) { plProcess.Visible = true; + + //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProcess)) + //{ + // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProcess)) + // { + // pCodes.Remove(SettingHelper.SettingInfo.DefaultProcess); + // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProcess); + // } + //} cboProcessCode.SelectedIndexChanged -= cboProcessCode_SelectedIndexChanged; UIHelper.SetCombo(cboProcessCode, pCodes, "", ""); @@ -104,6 +102,16 @@ if (pCodes.Count > 1) { plProduct.Visible = true; + + //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProduction)) + //{ + // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProduction)) + // { + // pCodes.Remove(SettingHelper.SettingInfo.DefaultProduction); + // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProduction); + // } + //} + cboProductionCode.SelectedIndexChanged -= cboProductionCode_SelectedIndexChanged; UIHelper.SetCombo(cboProductionCode, pCodes, "", ""); cboProductionCode.SelectedIndexChanged += cboProductionCode_SelectedIndexChanged; @@ -137,10 +145,12 @@ LogAsync(DateTime.Now, "杞藉叆娴佺▼"); LoadProcess(); + + SettingHelper.SetDefault(_processCode, _productionCode); } bool isStart = true; - private void btnStart_Click(object sender, System.EventArgs e) + private async void btnStart_Click(object sender, System.EventArgs e) { if (Process == null) { @@ -150,18 +160,15 @@ btnStart.Enabled = false; - //Task.Run(() => - //{ try { - //if (Process.ProcessState != EnumHelper.DeviceState.DSOpen) if (isStart) { - ProcessOperation(true); + await ProcessOperation(true); } else { - ProcessOperation(false); + await ProcessOperation(false); } isStart = !isStart; @@ -172,9 +179,8 @@ } finally { - this.BeginInvoke(new Action(() => btnStart.Enabled = true)); + btnStart.Enabled = true; } - //}); } string _currentProcssCode = ""; @@ -192,7 +198,7 @@ return; } - //Process.OnProcessStateChanged += Process_OnProcessStateChanged; + Process.OnLog -= Process_OnLog; Process.OnLog += Process_OnLog; _currentProcssCode = _processCode; @@ -209,80 +215,27 @@ LogAsync(dt, prefix, msg); } - //private void Process_OnProcessStateChanged(EnumHelper.DeviceState state) - //{ - // try - // { - // if (InvokeRequired) - // { - // this.Invoke(new Action<EnumHelper.DeviceState>(Process_OnProcessStateChanged), state); - // } - // else - // { - // try - // { - // btnStart.Enabled = true; - - // switch (state) - // { - // case EnumHelper.DeviceState.DSOpen: - // btnStart.Text = " 鍋� 姝�"; - // btnStart.ImageIndex = 1; - // btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen); - - // btnLoad.Enabled = false; - // break; - // case EnumHelper.DeviceState.DSClose: - // btnStart.Text = " 鍚� 鍔�"; - // btnStart.ImageIndex = 0; - // btnStart.BackColor = SystemColors.Control; - - // btnLoad.Enabled = true; - // break; - // default: - // break; - // } - - // this.Refresh(); - // } - // catch (Exception ex) - // { - // } - // } - // } - // catch (Exception ex) - // { - // } - //} - - private void ProcessOperation(bool isStart) + private async Task ProcessOperation(bool isStart) { if (isStart) { - Process.Open(); + await Task.Run(() => Process.Open()); - //this.BeginInvoke(new Action(() => - //{ btnStart.Text = " 鍋� 姝�"; btnStart.ImageIndex = 1; btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen); btnLoad.Enabled = false; - //})); - } else { - Process.Close(); + await Task.Run(() => Process.Close()); - //this.BeginInvoke(new Action(() => - //{ btnStart.Text = " 鍚� 鍔�"; btnStart.ImageIndex = 0; btnStart.BackColor = SystemColors.Control; btnLoad.Enabled = true; - //})); } } } -- Gitblit v1.8.0