Winform多线程使用委托操作控件

随手记录

private void barLargeButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
//重新加载数据
Thread DataThread = new Thread(new ThreadStart(LoadData));
DataThread.IsBackground = true;
DataThread.Start();
}

#region 加载数据
public void LoadData()
{
SetMarqueeProgress(true);

DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn() { ColumnName = "编号" });
dt.Columns.Add(new DataColumn() { ColumnName = "城市" });

SetDgvDataSource(dt);
SetMarqueeProgress(false);
}
#endregion

 

#region 委托操作
///


/// 显示隐藏等待条
///

///
delegate void mpDelegate(bool Visible);
private void SetMarqueeProgress(bool Visible)
{
if (marqueeProgressBarControl1.InvokeRequired)
{
marqueeProgressBarControl1.Invoke(new mpDelegate(SetMarqueeProgress), Visible);
}
else
{
marqueeProgressBarControl1.Visible = Visible;
}
}

///


/// 绑定数据
///

///
delegate void dgvDelegate(DataTable table);
private void SetDgvDataSource(DataTable table)
{
if (PointDataGrid.InvokeRequired)
{
PointDataGrid.Invoke(new dgvDelegate(SetDgvDataSource), table);
}
else
{
PointDataGrid.DataSource = table;
}
}
#endregion

转载于:https://www.cnblogs.com/tian2008/p/8087079.html

你可能感兴趣的:(Winform多线程使用委托操作控件)