0

I'm trying to have a progress bar running while reading a file. I'm not sure how to do this. Help is much appreciated. Code is below:

 UploadProgressBar.Visible = true; 
 UploadProgressBar.Value = 0;
 CurrentFile = reader.read(CurrentFileName); //need progress bar running during this code
 UploadProgressBar.Value = 100;
 UploadProgressBar.Visible = false;
 CurrentFileLabel.Text = CurrentFileName;
  • I placed the upload bar on a separate form, I think this solution may work better. Let me know of any other solutions, thanks! – Andre Davis Aug 21 '18 at 19:21

1 Answers1

0

You have to execute your reading operation in another thread, because in this way you're blocking the UI thread.

So 2 options here :

  1. Keep your current setup that seems working for you
  2. Launch your operation on another thread :
    await Task.Run(async() => CurrentFile = reader.read(CurrentFileName));

The problem here is that if your read() doesn't have a callback to inform you about the progress you'll not be able to update the progress par accordingly to the operation progress. It would probably be an easier option to implement an infinite progress bar here.

Selmir
  • 1,136
  • 1
  • 11
  • 21