Multi-thread neutron thread control progress bar (see MSDN)

xiaoxiao2021-03-31  178

private void button1_Click (object sender, System.EventArgs e) {flag = false; Thread thread = new Thread (new ThreadStart (target)); thread.IsBackground = true; thread.Start ();} public void target () {try {MethodInvoker Mi = New MethodInvoker (CountPro); While (! Flag) {this.invoke (mi); thread.sleep (1000);}} catch (threadInterruptedException e) {if (e! = Null) {}} catch Exception we) {if (we! = Null) {//messagebox.show (we.tostring ());}}

} Public void countPro () {int min; double numerator, denominator, completed; min = this.progressBar1.Minimum; if (this.progressBar1.Value == this.progressBar1.Maximum) {this.progressBar1.Value = this.progressBar1 .Minimum;} else {this.progressBar1.PerformStep ();} // this.textBox1.Text = this.progressBar1.Value.ToString progress display (); numerator = this.progressBar1.Value-min; denominator = this.progressBar1 .Maximum-this.progressbar1.minimum; completed = (numerator / denominator) * 100.0; this.label2.text = math.round (completed) "%"

Private void button2_click (object sender, system.eventargs e) {flag = true;

转载请注明原文地址:https://www.9cbs.com/read-130837.html

New Post(0)