MSDN 가이드에 따라 UI 컨트롤을 업데이트하는 새 스레드를 만든 후 이상한 오류가 발생합니다. 나는이 동일한 쿼리를 load 메소드에서 실행 시켰고, 이제는 결과가 옳은 새 스레드에서 실행되지만 필드 이름을 얻는 대신 ComboBox에 16 시간 쓴 DataSet을 가져온다. 아무도 이것으로 나를 도울 수 있습니까?새 스레드에서 Linq 쿼리를 실행하십시오.
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);
난이가이처럼 보였다 새 스레드에 넣어 전에 :이 데이터베이스에 16 개의 다른 레서피의 목록을 retrun 것
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);
, 지금은 단지 데이터 세트 16 번 인쇄 얻을.
도움 주셔서 감사합니다.
크레이그
코드에서 여기 _Text_ 같은 경우이다 : 그것은 당신의 문제입니다하지만 당신은 여기 케이싱 불일치가있는 경우
확실하지'this.recipeListComboBox.Items.Add (텍스트); '? –
답변에 넣어. 너는 나를 위해 그것을 가지고있어, 고마워! –
내 눈이 피곤해질 수도 있다고 생각합니다. 죄송합니다. –