C多线程的进度条
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApp4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private async void button1_Click(object sender, EventArgs e) { var progressHandler = new Progress(value => { label2.Text = "当前值:" + value; progressBar1.Value = Convert.ToInt32(value); }); var progress = progressHandler as IProgress; await Task.Run(() => { for (int i = 0; i != 100; ++i) { if (progress != null) progress.Report(i.ToString()); Thread.Sleep(100); } }); label2.Text = "Completed."; } } }