1

I'm doing network scanning application. The application works fine, just I want to add ProgressBar which show the progress start from when user click scanning until scan completed.

private void scanClick(object sender, System.EventArgs e)
{
    if (StatusLabel.Text == "Ready")
    {
        StatusLabel.Text = "Please wait while processing is done...";
    }  
    //scanning operation begins
    //label changed when scan completed
    StatusLabel.Text = "scan completed";                           
}

Now I have a progress bar something like this:
enter image description here

How to synchronize the progress bar with the scan job. Please advise.

Dmitry
  • 13,797
  • 6
  • 32
  • 48
Ren
  • 765
  • 4
  • 15
  • 42

2 Answers2

1
  • If you do not know the progress in between those two comments, then you can't sync your progress bar with the scanning operation

    //scanning operation begins
    //label changed when scan completed
    
  • One alternate is showing the progress bar moving left and right showing scanning is in progress and at the same time do not know when it will complete.

  • Use a Background thread to perform the Scanning operation, perform the progress update in the main thread

Sivaraman
  • 438
  • 2
  • 9
0

If you are doing some time consuming operation in the same thread, then update progress and call Application.DoEvents();.

If you are doing asynchronous operation, then update ProgressBar with Control.Invoke method.

Elvedin Hamzagic
  • 825
  • 1
  • 9
  • 22