Task ProgressBar TextBox display after the completion of the analog reality

private async void Form1_Load(object sender, EventArgs e)
        {
            progressBar1.Maximum = 10;
            progressBar2.Maximum = 20;
 
            MyControls mc1 = new MyControls() { pb = progressBar1, tb = textBox1 };
            MyControls mc2 = new MyControls() { pb = progressBar2, tb = textBox1 };
            Task.Factory.StartNew(myThread.fun, mc1);
            Task.Factory.StartNew(myThread.fun, mc2);
        }
 
        public class myThread       // create a thread of class to a similar process can call it 
        {
             public  static  void Fun ( Object mc) 
            { 
                MyControls MyControls = mc AS MyControls;
                 // simulate a progress bar 
                the while ! (MyControls.pb.Value = myControls.pb. the Maximum) 
                { 
                    myControls.pb.Invoke ( new new the Action (() => 
                    { 
                        myControls.pb.Value + = . 5 ; 
                    })); 
                    the Thread.Sleep ( 1000 );
                } 
                // After completion of the progress bar, textbox display information 
                myControls.tb.Invoke ( new new the Action (() => { 
                    myControls.tb.Text = myControls.pb.Value.ToString (); 
                })); 
            } 
        } 
 
        public  class the MyControls 
        { 
            public the ProgressBar Pb { GET ; SET ;}
             public the TextBox TB { GET ; SET ;} 
        }

image:

Guess you like

Origin www.cnblogs.com/hanjun0612/p/10955363.html