有一个使用 BinaryFormatter 序列化多个表的大型错误代码如何更新进度条?执行序列化的代码是: private void Serialize() { try { int numberTableProcessed = 0; txtBoxProcessing.Text += "Start ..." + DateTime.Now + Environment.NewLine; AGENTS agenti = new AGENTS(); agenti.SelectAndSerializeAgenti(openedConn); string pathAgenti = @"C:\...AGENTS.bin"; if (File.Exists(pathAgenti)) { long size = new FileInfo(pathAgenti).Length; txtBoxProcessing.Text += "Processed AGENTI - " + string.Format("byte: {0:n}", size) + Environment.NewLine; } numberTableProcessed++; UpdateProgressBar(numberTableProcessed); PRODUCT anaart = new PRODUCT(); anaart.SelectAndSerializeAnaart(openedConn); string pathAnaart = @"C:\...PRODUCT.bin"; if (File.Exists(pathAnaart)) { long size = new FileInfo(pathAnaart).Length; txtBoxProcessing.Text += "Processed PRODUCT - " + string.Format("byte: {0:n}", size) + Environment.NewLine; } numberTableProcessed++; UpdateProgressBar(numberTableProcessed); ...}更新进度条的代码private void UpdateProgressBar(int numberTableProcessed) { int numberTotalTables = 22; progressBar1.Value = (numberTableProcessed / numberTotalTables) * 100; }使用方法 UpdateProgressBar 我看不到进度......最后它变成全绿色,因为代码正在运行(我认为)如何更新进度条?我根据路西法的建议尝试这个public Form1() { InitializeComponent(); backgroundWorker1.DoWork += backgroundWorker1_DoWork; } public void PerformSerialize() { backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Serialize(); }
1 回答
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消