我正在执行一个 DLL,它使用它通过引用backgroundWorker1
更新变量。i
要使用 更新进度条i
,我使用以下代码。我还想将百分比显示为文本。问题是文本(不是进度条)闪烁很多。如何减少/消除这种闪烁?增加睡眠时间不是一种选择。
BackgroundWorker backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += (s, args) =>
{
Mydll.MyCFunction(ref i);
};
backgroundWorker1.RunWorkerAsync();
while (backgroundWorker1.IsBusy)
{
backgroundWorker1.ReportProgress(i * 100);
backgroundWorker1.ProgressChanged += (s, e) =>
{
progressBar1.Refresh();
progressBar1.Value = e.ProgressPercentage;
progressBar1.CreateGraphics().DrawString(e.ProgressPercentage.ToString() + "%",
SystemFonts.DefaultFont, Brushes.Black,
new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));
};
Application.DoEvents();
System.Threading.Thread.Sleep(200);
}
谢谢。