//子线程调用主线程方法一
//this.Invoke(new Action(() => {
// dgvScanChip.DataSource = SaveChipList;
//}));
//子线程调用主线程方法一
//ControlInvoker.Invoke(this, delegate
//{
// dgvScanChip.DataSource = SaveChipList;
//});
public static class ControlInvoker
{
private static readonly Logger logger = LogManager.GetLogger("DefaultLog");
public static void Invoke(Control ctl, MethodInvoker method)
{
try
{
if (!ctl.IsHandleCreated)
return;
if (ctl.IsDisposed)
return;
if (ctl.InvokeRequired)
{
ctl.Invoke(method);
}
else
{
method();
}
}
catch (Exception ex)
{
logger.Error(ex, "ControlInvoker异常");
}
}
}