//进度条所需变量
private int IsSucess = -1;//判断数据库操作是否成功
public delegate int ProcessDataDelegate(string buildID);public BuildEnergyEx()
{
InitializeComponent();
this.gvList.AutoGenerateColumns = false;
this.gvList.AllowUserToAddRows = false;
BindData(currentPage);
}
/// <summary>
/// 响应删除,忽略按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (this.gvList.Columns[e.ColumnIndex].Name == "btnDel")
{
//开启多线程调用进度条
processingBuildID = this.gvList.Rows[e.RowIndex].Cells["BuildID"].Value.ToString();
ProcessDataDelegate d1 = processData;
IAsyncResult ar = d1.BeginInvoke(processingBuildID, null, null);
//while (!ar.IsCompleted)
//{
//}
//int result = d1.EndInvoke(ar);
ProcessOperator process = new ProcessOperator();
process.MessageInfo = "正在拼命处理中,请稍候...";
process.BackgroundWork = this.Do;
process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(process_BackgroundWorkerCompleted);
process.Start();
}
}
//委托方法
{
//进行能耗数据的更新
return IsSucess = BuildOperatorBLL.GetDataCorrectByID(processingBuildID);
}
#region 增加进度条
void process_BackgroundWorkerCompleted(object sender, BackgroundWorkerEventArgs e)
{
if (e.BackGroundException == null)
{
BindData(currentPage);
MessageBox.Show("执行完毕");
}
else
{
MessageBox.Show("异常:" + e.BackGroundException.Message);
}
}
void Do()
{
while (IsSucess < 0)
{
Thread.Sleep(20);
}
}
#endregion