I am executing a DLL using backgroundWorker1 which updates a variable i by reference. To update a progress bar using i, I use the following code. I also want to show the percentage as text. The problem is that the text (NOT the progress bar) flickers a lot. How can I reduce/remove this flicker? Increasing sleep duration is not an option.
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);
}
Thanks.
 
     
     
     
     
    