While I understand with async \ await I decided to make another backup option if nothing happens with async \ await. While the program will think, let the ProgressBar fill.
private void button1_Click(object sender, EventArgs e) { int T = Convert.ToInt32(textBox1.Text); int U = Convert.ToInt32(textBox2.Text); double shag = Convert.ToDouble(textBox3.Text); int frc = Convert.ToInt32(textBox4.Text); int frc1 = Convert.ToInt32(textBox5.Text); int frequency, counter; List<Complex> values = new List<Complex>(); progressBar1.Value = 0; var timer = new System.Windows.Forms.Timer(); timer.Interval = 100; timer.Tick += (s, a) => { progressBar1.Value += 5; if (progressBar1.Value == progressBar1.Maximum) { timer.Stop(); button1.Enabled = true; } }; timer.Start(); for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { values.Add(reverstrans(U, frequency, T, frc, frc1,shag)); } values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary)); drawreverse(U,T, shag, frc, frc1); drawgraph(U, T, frc, frc1, frequency, shag); } As soon as the calculations end then he is immediately green.
But it was planned to fill it in as the calculation process, thereby improving the interface of the program.
After the code I changed
private void button1_Click(object sender, EventArgs e) { int T = Convert.ToInt32(textBox1.Text); int U = Convert.ToInt32(textBox2.Text); double shag = Convert.ToDouble(textBox3.Text); int frc = Convert.ToInt32(textBox4.Text); int frc1 = Convert.ToInt32(textBox5.Text); int frequency, counter; List<Complex> values = new List<Complex>(); progressBar1.Maximum = 100; for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { values.Add(reverstrans(U, frequency, T, frc, frc1,shag)); progressBar1.Value += frequency ; } values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary)); drawgraph(U, T, frc, frc1, frequency, shag); drawreverse(U, T, shag, frc, frc1); } but an exception popped up and at the same time, from where he adds to my ProgressBar1.Maximum, the number 28.
I tried changing the settings step and maximum but the exception crashed and those cases and returned to the original parameters
I looked at similar questions and my code coincides partly with what they have. But knocks an exception.

