-1

I have multiple BackgroundWorker components downloading data and they update a respective ListViewItem with the progress. The ListView control flickers intensely when the downloading process begins.

private void btnDownload_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < videos.Count; i++)
        {
            var index = i;
            BackgroundWorker worker = new BackgroundWorker
            {
                WorkerReportsProgress = true
            };
            worker.DoWork += delegate
            {
                if (videos[index].RequiresDecryption)
                    DownloadUrlResolver.DecryptDownloadUrl(videos[index]);
                AudioDownloader audioDownloader = new AudioDownloader(videos[index], Path.Combine(Settings.Default.DownloadLocation,
                    RemoveIllegalPathCharacters(videos[index].Title) + videos[index].AudioExtension));
                audioDownloader.AudioExtractionProgressChanged += (s, args) =>
                    {
                        int num = (int)Math.Round((decimal)(85 + args.ProgressPercentage * 0.15));
                        worker.ReportProgress(num);
                    };
                audioDownloader.DownloadProgressChanged += (s, args) =>
                    {
                        int num = (int)Math.Round((decimal)(args.ProgressPercentage * 0.85));
                        worker.ReportProgress(num);
                    };
                audioDownloader.Execute();
            };
            worker.ProgressChanged += (s, args) =>
                {
                    lstQueue.Items[index].SubItems[2].Text = args.ProgressPercentage.ToString();
                };
            worker.RunWorkerAsync();
        }
    }

How can I eliminate the flicker? I've tried setting DoubleBuffered to true for the parent form but that did not work.

Minato
  • 352
  • 3
  • 13

1 Answers1

0

It was very simple. All I needed to do was create a custom control that inherited form the ListView and call SetStyle(ControlStyles.OptimizedDoubleBuffer, true); in the constructor.

Minato
  • 352
  • 3
  • 13