1. 程式人生 > >Winform多線程使用委托操作控件

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

item eve poi log load summary 使用 winform inf

隨手記錄

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 委托操作
/// <summary>
/// 顯示隱藏等待條
/// </summary>
/// <param name="Visible"></param>
delegate void mpDelegate(bool Visible);
private void SetMarqueeProgress(bool Visible)
{
if (marqueeProgressBarControl1.InvokeRequired)
{
marqueeProgressBarControl1.Invoke(new mpDelegate(SetMarqueeProgress), Visible);
}
else
{
marqueeProgressBarControl1.Visible = Visible;
}
}

/// <summary>
/// 綁定數據
/// </summary>
/// <param name="table"></param>
delegate void dgvDelegate(DataTable table);
private void SetDgvDataSource(DataTable table)
{
if (PointDataGrid.InvokeRequired)
{
PointDataGrid.Invoke(new dgvDelegate(SetDgvDataSource), table);
}
else
{
PointDataGrid.DataSource = table;
}
}
#endregion

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