Browse Source

..

master
Robin_PC\robin 18 hours ago
parent
commit
5ba5df25fe
1 changed files with 21 additions and 19 deletions
  1. +21
    -19
      ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs

+ 21
- 19
ButcherFactory.Form/SegmentProductionAuto_/SegmentProductionAutoForm.cs View File

@ -103,16 +103,26 @@ namespace ButcherFactory.SegmentProductionAuto_
// 新增方法:显示错误,5秒自动清空 // 新增方法:显示错误,5秒自动清空
private void ShowErrorMsg(string msg) 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 里面释放定时器 // FormClosing 里面释放定时器
void SegmentProductionAutoForm_FormClosing(object sender, FormClosingEventArgs e) void SegmentProductionAutoForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
@ -223,11 +233,7 @@ namespace ButcherFactory.SegmentProductionAuto_
var msg = ex.Message ?? string.Empty; var msg = ex.Message ?? string.Empty;
if (!IsDisposed) if (!IsDisposed)
{ {
this.Invoke(new Action(() =>
{
if (IsDisposed) return;
ShowErrorMsg(msg);
}));
ShowErrorMsg(msg);
} }
LogUtil.WriteErrorFile(msg, "分割品车间称重计数"); LogUtil.WriteErrorFile(msg, "分割品车间称重计数");
} }
@ -838,14 +844,10 @@ namespace ButcherFactory.SegmentProductionAuto_
{ {
if (_isFormClosing || IsDisposed) return; if (_isFormClosing || IsDisposed) return;
if (!IsDisposed) if (!IsDisposed)
{
this.Invoke(new Action(() =>
{
if (IsDisposed) return;
var msg = ex.Message ?? string.Empty;
{
var msg = ex.Message ?? string.Empty;
ShowErrorMsg(msg); ShowErrorMsg(msg);
LogUtil.WriteErrorFile(msg, "分割品车间称重计数");
}));
LogUtil.WriteErrorFile(msg, "分割品车间称重计数");
} }
} }
Thread.Sleep(5000); Thread.Sleep(5000);


Loading…
Cancel
Save