我有一个长时间运行的方法,所以我创建了一个进度条来显示我的方法完成的百分比,但我很难弄清楚如何做到这一点,将我的进度条与我的方法同步 => excelHelper.InsertNewRows(); 。
public void ButtonSubmit_Click(object sender, EventArgs e)
{
if (isProcessRunning)
{
MessageBox.Show("A Process is aleady running");
return;
}
Thread backgroundThread = new Thread(
new ThreadStart(() =>
{
for (int n = 0; n < 100; n++)
{
isProcessRunning = true;
Thread.Sleep(50);
progressBar1.Invoke(
new Action(() =>
{
progressBar1.Value = n;
label3.Text = ("Progress: " + n + "%");
}
));
}
MessageBox.Show("Thread completed!");
progressBar1.Invoke(
new Action(() =>
{
progressBar1.Value = 0;
}
));
isProcessRunning = false;
}
));
backgroundThread.Start();
excelHelper.InsertNewRows();
var folder = TextOutputFile.Text + @"\" +
DateTime.Now.ToString("yyyy_MM_dd_") + "SA_Analysis_Report.xlsx";
excelHelper.Save(folder);
MessageBox.Show("File has been added to file");
}
子衿沉夜
UYOU
慕妹3146593
相关分类