This question has already been answered:

There is a form, I need to call it in another thread, and simultaneously change the Value parameter of the progressBar.

int precentage = f1.Allcount / 100; while (ChkedComplete) { if (countCheked / precentage > 100) { ProgressBar1.Value = 100; } else { ProgressBar1.Value = countCheked / precentage; } panel2.Visible = true; } 

how to implement all this?

Reported as a duplicate by Pavel Mayorov c # Jan 15 '18 at 10:02 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    1) You can run the form in a separate thread through Task , passing the delegate of the required type.

    2) Control is tied to the stream in which it was created => you cannot change it from the outside as easily as you actually understood.

    Therefore, InvokeRequired comes to help us, which allows us to understand whether Invoke needs to be called to apply to the control.

    An example is taken from here :

     private void SetText(string text) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.textBox1.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetText); this.Invoke(d, new object[] { text }); } else { this.textBox1.Text = text; } } 
    • one
      What is a minus ..? - iluxa1810