I've got a program with a progress bar that doesn't update until the program is finished. I did some digging and figured out that I need to make a background worker so that it will update as my while loop runs. From the examples shown I'm just not getting what I'm supposed to do. Can someone explain to me how to set this up and what it is doing please?
int progressBar;
private void button3_Click(object sender, EventArgs e)
{
try
{
while (y < PriDID.Count)
{
cmd.CommandText = "SELECT COUNT(*) FROM Accounts WHERE ACCT='" + ACCT[y] + "'";
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count < 1)
{
progressBar = (y / SDM_ACCT.Count) * 100;
progressBar1.Value = progressBar;
progressBar1.Update();
Console.WriteLine(SDM_ACCT[y - 1]);
cmd.CommandText = @"INSERT INTO Accounts(SDM_ACCT,Description)
values(" + "'" + ACCT[y] + "'," + "'" + Comment[y] + ")";
cmd.ExecuteNonQuery();
y++;
recordCount++;
}
else
{
y++;
}
MessageBox.Show(recordCount + " unique records successfully loaded to the Database.");
}
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message + " Please make sure you have selected a valid path for your CSV and database.");
}
}