110,567
社区成员
发帖
与我相关
我的任务
分享
private void btnStep1_Click(object sender, EventArgs e)
{
ReadExcelDelegate red = new ReadExcelDelegate(ReadExcel);
red.BeginInvoke(null, null);
}
private delegate void ReadExcelDelegate();
private void ReadExcel()
{
for (int i = 0; i < 100000; i++)
{
i = i + 1;
ShowProgress(i.ToString());
}
}
//UI显示
delegate void ShowProgressDelegate(string con);
void ShowProgress(string con)
{
// 确保在正确的线程上
if (this.textBox1.InvokeRequired == false)
{
this.textBox1.Text = con;
}
else
{
// 异步显示进度
ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress);
this.textBox1.BeginInvoke(showProgress, new object[] { con });
}
}
private delegate void ReadExcelDelegate();
private void ReadExcel()
{
for (int i = 0; i < 100000; i++)
{
i = i + 1;
Thread.Sleep(1);
ShowProgress(i.ToString());
}
}
//UI显示
delegate void ShowProgressDelegate(string con);
void ShowProgress(string con)
{
// 确保在正确的线程上
if (this.textBox1.InvokeRequired == false)
{
this.textBox1.Text = con;
}
else
{
// 异步显示进度
ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress);
this.textBox1.BeginInvoke(showProgress, new object[] { con });
}
}