问题描述:

This question already has an answer here:

  • Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on

    15 answers

网友答案:

You should consider using the Task Parallel Library, creating a Thread explicitly is considered legacy code nowadays. However, to fix your code, you need to invoke the UI updates on the UI Thread.

public void Fill()
{
   Thread.Sleep(5000);

   Action doUIWork = () => 
   {
      ComboBox1.Items.Add(1);
      ComboBox1.Items.Add(2);
      ComboBox1.Items.Add(3);
      ComboBox1.Items.Add(4);
      ComboBox1.Items.Add(5);
      ComboBox1.Items.Add(6);
      ComboBox1.Items.Add(7);
   };

   this.Invoke(doUIWork);
}
相关阅读:
Top