110,538
社区成员
发帖
与我相关
我的任务
分享
System.Threading.ManualResetEvent obj = new ManualResetEvent(true);
private void ImportToDataBase()
{
DataTable dt = GetData();
//int rsCount = dt.Rows.Count;
int rsCount = 100;
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = rsCount;
this.progressBar1.Step = 1;
int exeCount = 0;
while (exeCount != rsCount)
{
while (obj.WaitOne(100, false) == false) { };
//从dt从获取数据整理后插入数据库
//.......
exeCount++;
this.progressBar1.Value = exeCount;
Thread.Sleep(100);
}
}
private void button1_Click(object sender, EventArgs e)
{
Form.CheckForIllegalCrossThreadCalls = false;
Thread thd = new Thread(new ThreadStart(ImportToDataBase));
thd.Start();
}
private void button2_Click(object sender, EventArgs e)
{
obj.Reset();
}
private void button3_Click(object sender, EventArgs e)
{
obj.Set();
}