c# 进度条的使用(例子)、线程
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace ProgressBar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//更新进度列表
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.label1.Text = ipos.ToString() + "/100";
this.progressBar1.Value = Convert.ToInt32(ipos);
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread fThread = new Thread(new ThreadStart(SleepT));//开辟一个新的线程
fThread.Start();
}
private void SleepT()
{
for (int i = 0; i < 500; i++)
{
System.Threading.Thread.Sleep(100);//没什么意思,单纯的执行延时
SetTextMessage(100 * i / 500);
}
}
}
}