WinFrom异步加载数据,不卡主线程
private async Task GetPackageNo(string mo)
{
await Task.Run(() =>
{
DataTable main_dt=new DataTable();
int Count = int.Parse(ADO.ExecuteScalar($"SELECT COUNT(*) FROM SHELL_BIND_CELL WHERE SHELL_BARCODE in(SELECT b.BARCODE FROM PACK_MAIN a LEFT JOIN PACK_DETAIL b ON a.PACK_NO=b.PACK_NO WHERE a. MO='{mo}')").ToString());
if (Count == 0)
{
ADO.sqlString = $"SELECT a.MO AS 生产工单, a.PACK_NO AS 箱号,b.BARCODE AS 电芯 FROM PACK_MAIN a LEFT JOIN PACK_DETAIL b ON a.PACK_NO=b.PACK_NO WHERE a. MO='{mo}' order by a.id";
main_dt = ADO.ExecuteDataTable(ADO.sqlString);
}
this.BeginInvoke(new Action(() =>
{
gridControl13.DataSource = main_dt;
}));
});
}
{
await Task.Run(() =>
{
DataTable main_dt=new DataTable();
int Count = int.Parse(ADO.ExecuteScalar($"SELECT COUNT(*) FROM SHELL_BIND_CELL WHERE SHELL_BARCODE in(SELECT b.BARCODE FROM PACK_MAIN a LEFT JOIN PACK_DETAIL b ON a.PACK_NO=b.PACK_NO WHERE a. MO='{mo}')").ToString());
if (Count == 0)
{
ADO.sqlString = $"SELECT a.MO AS 生产工单, a.PACK_NO AS 箱号,b.BARCODE AS 电芯 FROM PACK_MAIN a LEFT JOIN PACK_DETAIL b ON a.PACK_NO=b.PACK_NO WHERE a. MO='{mo}' order by a.id";
main_dt = ADO.ExecuteDataTable(ADO.sqlString);
}
this.BeginInvoke(new Action(() =>
{
gridControl13.DataSource = main_dt;
}));
});
}