in my form i have a textbox, background worker and a data grid view. using the textbox(TextChanged property) i want to fatch data using the background worker and fill matching data in the data grid view as i type.
here is what i have tried out.
private void txtSearchBox_TextChanged(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy)
{
backgroundWorker1.CancelAsync();
}
backgroundWorker1.RunWorkerAsync();///Runs the background worker
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter("select * from Games where Name like '%" + txtSearchBox.Text + "%'", con);
da.Fill(ds, "GameID");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
SimilarData.DataSource = ds.Tables["GameID"].DefaultView;
}
With that am getting this error. ErrorSystem.InvalidOperationExceptoin:This Background worker is currently busyand and not run multiple tasks concurrently.
What do i do?
