When I click the button, the form is waiting for a while after the progressbar is completed.. For a while, it is giving a message that the data is recorded.. What do you think is the reason for this? My codes are here.

private IProgress<int> progress;
public void DoProcessing(IProgress<int> progress)
{
for (int i = 0; i <= 100; ++i)
{
Thread.Sleep(100); // CPU-bound work
if (progress != null)
progress.Report(i);
}
}
private async void button3_Click(object sender, EventArgs e)
{
List<int> ChkedRow = dataGridView1.Rows.Cast<DataGridViewRow>()
.Where(row => Convert.ToBoolean(row.Cells[0].Value) == true)
.Select(row => row.Index)
.ToList();
if (ChkedRow.Count == 0)
{
MessageBox.Show("Geziye katilacak ögrenci seçiminde bulunmadiniz!");
return;
}
label5.Visible = true;
progressBar1.Value = 0;
progressBar1.Visible = true;
Cursor.Current = Cursors.WaitCursor;
var progress = new Progress<int>(percent =>
{
progressBar1.Value = percent;
progressBar1.PerformStep();
label5.Text = percent.ToString() + "%";
});
// DoProcessing is run on the thread pool.
await Task.Run(() => DoProcessing(progress));
foreach (int j in ChkedRow)
{
try
{
var val1 = dataGridView1.Rows[j].Cells["tcno"].Value;
var val2 = dataGridView1.Rows[j].Cells["ono"].Value;
var val3 = dataGridView1.Rows[j].Cells["isim"].Value;
var val4 = dataGridView1.Rows[j].Cells["soyisim"].Value;
var val5 = dataGridView1.Rows[j].Cells["cinsiyet"].Value;
var val6 = dataGridView1.Rows[j].Cells["dtarihi"].Value;
var val7 = dataGridView1.Rows[j].Cells["sinifi"].Value;
var val8 = dataGridView1.Rows[j].Cells["unvan"].Value;
var val10 = dataGridView1.Rows[j].Cells["kbaskani"].Value;
using (var conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = gezievrak2541.accdb; Jet OLEDB:Database Password = Fatih2541; Mode = ReadWrite"))
{
conn.Open();
using (var cmd = new OleDbCommand("select * from gezilistemiz25 where tcno IN ('" + val1 + "')", conn))
{
using (OleDbDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
while (dr.Read())
{
MessageBox.Show(" '" + val3 + " " + val4 + "' isimli ögrenciler veritabaninda kayitlidir. Mükerrer kayit yapilamaz. Lütfen kontrol ediniz.");
}
}
else
{
string val9 = null;
if (!String.IsNullOrEmpty(dataGridView1.Rows[j].Cells["atel"].Value.ToString()))
{
val9 = dataGridView1.Rows[j].Cells["atel"].Value.ToString();
}
else if (!String.IsNullOrEmpty(dataGridView1.Rows[j].Cells["btel"].Value.ToString()))
{
val9 = dataGridView1.Rows[j].Cells["btel"].Value.ToString();
}
else
{
MessageBox.Show("'" + val3 + " " + val4 + "' isimli ögrencinin veli telefonu bulunmamaktadir! Bu nedenle bu ögrenci gezi listesine eklenemedi.");
continue;
}
var cmdText = "INSERT INTO gezilistemiz25 (tcno, ono, adi, soyadi, cinsiyet, dtarihi, sinifi, unvani, vtel, kbaskani) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
var command = new OleDbCommand(cmdText, conn);
command.Parameters.AddWithValue("tcno", val1);
command.Parameters.AddWithValue("ono", val2);
command.Parameters.AddWithValue("adi", val3);
command.Parameters.AddWithValue("soyadi", val4);
command.Parameters.AddWithValue("cinsiyet", val5);
command.Parameters.AddWithValue("dtarihi", val6);
command.Parameters.AddWithValue("sinifi", val7);
command.Parameters.AddWithValue("unvani", val8);
command.Parameters.AddWithValue("vtel", val9);
command.Parameters.AddWithValue("kbaskani", val10);
command.ExecuteNonQuery();
conn.Close();
command.Dispose();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
progressBar1.Visible = false;
label5.Visible = false;
headerCheckBox2.Checked = false;
comboBox1.SelectedIndex = 0;
GC.WaitForPendingFinalizers();
GC.Collect();
MessageBox.Show("Seçtiginiz ögrenciler gezi listesine eklendi.");
Listele();
Cursor.Current = Cursors.Arrow;
}