private void btnStart_Click(object sender, EventArgs e)
{
// 线程控制进度条
new Thread(new ThreadStart(DoEvent)).Start();
}
private delegate void MoveProgressDelegate(int nCurrent);
private event MoveProgressDelegate eventMoveProgress;
private void DoEvent()
{
eventMoveProgress += new MoveProgressDelegate(MoveProgress);
DoThings();
}
private void MoveProgress(int nCurrent)
{
if (this.InvokeRequired)
{
this.Invoke(new MoveProgressDelegate(MoveProgress), new object[] { nCurrent });
}
else
{
this.progressBar1.Value = nCurrent;
this.labelPcntValue.Text = nCurrent.ToString() + " %";
}
}
private void DoThings()
{
// 计算函数,根据计算进度实时改变进度条的值
int MAX = 10000;
int value = 0;
for (int i = 1; i < MAX; i++)
{
value = i * 3.14;
iPosition = (int)Math.Floor(i / MAX * 100);
MoveProgress(iPosition);
}
}
多线程控制进度条
最新推荐文章于 2016-01-18 02:19:44 发布