protected void btncreatedata_Click(object sender, EventArgs e)
{
//开辟一个新的线程
Thread fThread = new Thread(new ThreadStart(SleepT));
fThread.Start();
}
//定义一个代理,用于更新ProgressBar的值(Value)
private delegate void SetPos(int ipos);
//进度条值更新函数(参数必须跟声明的代理参数一样)
private void SetTextMessage(int ipos)
{
if (this.InvokeRequired)
{
SetPos setpos = new SetPos(SetTextMessage);
this.Invoke(setpos, new object[] { ipos });
}
else
{
this.progressBar1.Value = Convert.ToInt32(ipos);
lblcount.Text = "正在生成第" + ipos.ToString() + "条数据...";
if (ipos ==1001)
{
lblcount.Text = "导入完成。";
}
}
}
//数据导入线程方法
private void SleepT()
{
for (int i = 1; i <= 1001; i++)
{
SetTextMessage(i);
}
}
页面拖个ProgressBar 长度设置MAXINUM 1001
{
//开辟一个新的线程
Thread fThread = new Thread(new ThreadStart(SleepT));
fThread.Start();
}
//定义一个代理,用于更新ProgressBar的值(Value)
private delegate void SetPos(int ipos);
//进度条值更新函数(参数必须跟声明的代理参数一样)
private void SetTextMessage(int ipos)
{
if (this.InvokeRequired)
{
SetPos setpos = new SetPos(SetTextMessage);
this.Invoke(setpos, new object[] { ipos });
}
else
{
this.progressBar1.Value = Convert.ToInt32(ipos);
lblcount.Text = "正在生成第" + ipos.ToString() + "条数据...";
if (ipos ==1001)
{
lblcount.Text = "导入完成。";
}
}
}
//数据导入线程方法
private void SleepT()
{
for (int i = 1; i <= 1001; i++)
{
SetTextMessage(i);
}
}
页面拖个ProgressBar 长度设置MAXINUM 1001