|
|
|
@ -103,16 +103,26 @@ namespace ButcherFactory.SegmentProductionAuto_ |
|
|
|
// 新增方法:显示错误,5秒自动清空
|
|
|
|
private void ShowErrorMsg(string msg) |
|
|
|
{ |
|
|
|
if (IsDisposed) return; |
|
|
|
this.Invoke(new Action(() => |
|
|
|
// 先判断,并且使用 ISynchronizeInvoke 的方式安全发起invoke
|
|
|
|
if (IsDisposed || !IsHandleCreated) |
|
|
|
return; |
|
|
|
try |
|
|
|
{ |
|
|
|
if (IsDisposed) return; |
|
|
|
msglbl.Text = "ERROR:" + msg; |
|
|
|
_msgClearTimer.Stop(); |
|
|
|
_msgClearTimer.Start(); |
|
|
|
})); |
|
|
|
this.Invoke(new Action(() => |
|
|
|
{ |
|
|
|
if (IsDisposed) return; |
|
|
|
msglbl.Text = "ERROR:" + msg; |
|
|
|
_msgClearTimer.Stop(); |
|
|
|
_msgClearTimer.Start(); |
|
|
|
})); |
|
|
|
} |
|
|
|
catch (ObjectDisposedException) |
|
|
|
{ |
|
|
|
// 窗体已经释放,直接吞掉,不报错
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FormClosing 里面释放定时器
|
|
|
|
void SegmentProductionAutoForm_FormClosing(object sender, FormClosingEventArgs e) |
|
|
|
{ |
|
|
|
@ -223,11 +233,7 @@ namespace ButcherFactory.SegmentProductionAuto_ |
|
|
|
var msg = ex.Message ?? string.Empty; |
|
|
|
if (!IsDisposed) |
|
|
|
{ |
|
|
|
this.Invoke(new Action(() => |
|
|
|
{ |
|
|
|
if (IsDisposed) return; |
|
|
|
ShowErrorMsg(msg); |
|
|
|
})); |
|
|
|
ShowErrorMsg(msg); |
|
|
|
} |
|
|
|
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); |
|
|
|
} |
|
|
|
@ -838,14 +844,10 @@ namespace ButcherFactory.SegmentProductionAuto_ |
|
|
|
{ |
|
|
|
if (_isFormClosing || IsDisposed) return; |
|
|
|
if (!IsDisposed) |
|
|
|
{ |
|
|
|
this.Invoke(new Action(() => |
|
|
|
{ |
|
|
|
if (IsDisposed) return; |
|
|
|
var msg = ex.Message ?? string.Empty; |
|
|
|
{ |
|
|
|
var msg = ex.Message ?? string.Empty; |
|
|
|
ShowErrorMsg(msg); |
|
|
|
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); |
|
|
|
})); |
|
|
|
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); |
|
|
|
} |
|
|
|
} |
|
|
|
Thread.Sleep(5000); |
|
|
|
|