转载:https://blog.csdn.net/ym296900664/article/details/52192289
private delegate void SetPos(int ipos, string vinfo);//代理
/// <summary>
/// 进度条值更新函数(参数必须跟声明的代理参数一样)
/// </summary>
/// <param name="ipos"></param>
/// <param name="vinfo"></param>
private void SetTextMesssage(int ipos, string vinfo)
{
if (this.InvokeRequired)
{
SetPos setpos = new SetPos(SetTextMesssage);
this.Invoke(setpos, new object[] { ipos, vinfo });
}
else
{
this.label2.Text = ipos.ToString() + "/"+ coun;
this.progressBar1.Value = Convert.ToInt32(ipos);
// this.textBox1.AppendText(vinfo);
}
}
/// <summary>
/// 新的线程执行函数:自己的程序方法
/// </summary>
private void SleepT()
{
for (int i = 0; i < coun; i++)
{
System.Threading.Thread.Sleep(10);
//SetTextMesssage(100 * i / coun, i.ToString() + "\r\n");
SetTextMesssage(i, i.ToString() + "\r\n");
}
//coun是表中数据总行数
}
//实现
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread fThread = new Thread(new ThreadStart(SleepT));
fThread.Start();
}
```
//个人后续学习使用