当我单击按钮运行我的代码时,我的win表单会锁定并且我的进度条不会运行.我究竟做错了什么?
foreach (string barcount in idit)
{
barcountmax++;
}
label2.Text = "Total entries: " + barcountmax;
progressBar1.Minimum = 0;
progressBar1.Maximum = barcountmax;
...
foreach (string ids in idit)
{
string[] splitids = ids.Split('|');
string fixcommacrap = "";
barmovement++;
progressBar1.Value = barmovement;
}
Run Code Online (Sandbox Code Playgroud)
我的Winform只是锁定和冻结,我无法看到进度条.
我的猜测是你正在UI线程中完成所有工作.不要那样做.
用BackgroundWorker做工作,定期适当地更新进度条,采用ReportProgress允许在UI线程中要进行的UI变化.
如果你搜索BackgroundWorker教程,你会找到一大堆教程,比如这个.许多人会使用进度条给出示例,因为BackgroundWorker它几乎是针对该场景设计的.
| 归档时间: |
|
| 查看次数: |
1861 次 |
| 最近记录: |