After following the MSDN guide to create a new thread to update a UI control I’m getting a strange error. I had this same query run in the load method and it worked just fine, now running in the new thread I get the right number of results, but instead of getting the names of the fields I just get DataSet written 16 time in my comboBox. Can anyone help me with this?
private void Form1_Load(object sender, EventArgs e)
{
recipeListComboBox.Items.Clear();
Thread QueryThread = new Thread(new ThreadStart(updateRecipeList));
QueryThread.Start();
}
private void updateRecipeList()
{
IEnumerable<string> list = recipeList.getList();
foreach (string a in list)
UpdateRecipeComboBox(a);
}
private void UpdateRecipeComboBox(string text)
{
if (this.recipeListComboBox.InvokeRequired)
{
UpdateRecipeComboBoxCallBack d = new UpdateRecipeComboBoxCallBack(UpdateRecipeComboBox);
Invoke(d, new object[] { text });
}
else
{
this.recipeListComboBox.Items.Add(Text);
}
}
delegate void UpdateRecipeComboBoxCallBack(string text);
before I put this on a new thread it looked like this:
private void Form1_Load(object sender, EventArgs e)
{
recipeListComboBox.Items.Clear();
IEnumerable<string> list = recipeList.getList();
foreach (string a in list)
recipeComboBox.Items.Add(a);
this would retrun a list of 16 different recipies in the database, now I just get dataSet printed 16 times.
Thanks for any help!!
Craig
If you’re getting
"DataSet"printed over an over again I’m guessing that somewhere you’re using aDataSetobject in place of a string parameter and it’s callingobject.ToString()automatically which returns the name of the class.Not sure if it’s your problem but you also have a casing mismatch here: