以下程序.在ListBox 一直没有输出.为什么啊?这问题困扰我一个晚上了!
namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            Thread newth = new Thread(new ThreadStart(f.insetString));
            newth.Start();
        }
        private void insetString()
        {
            while (true)
            {
                this.listBox1.Items.Add("bsbsbsbsbsbsbsbsbs");
                Thread.Sleep(1000);
            }
        }
    }
}

解决方案 »

  1.   

    为什么要重新new 1个form
            private void button1_Click(object sender, EventArgs e) 
            { 
                Thread newth = new Thread(new ThreadStart(insetString)); 
                newth.Start(); 
            } 
            private void insetString() 
            { 
                while (true) 
                { 
                    this.listBox1.Items.Add("bsbsbsbsbsbsbsbsbs"); 
                    Thread.Sleep(1000); 
                } 
            } 
    试试
      

  2.   

    我测试了没问题啊
     Control.CheckForIllegalCrossThreadCalls = false; 设置了吗
      

  3.   

    在Form1_Load事件里加上红色那句话
     private void button2_Click(object sender, EventArgs e)
            {
                Thread newth = new Thread(new ThreadStart(this.insetString));
                newth.Start();         }
            private void insetString()
            {
                while (true)
                {
                     this.listBox1.Items.Add("bsbsbsbsbsbsbsbsbs");
                    Thread.Sleep(1000);
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {
                System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; 
            } 
      

  4.   

    如果用1楼的仿佛会出现个异常: 线程间操作无效: 从不是创建控件“listBox1”的线程访问它。
      

  5.   

    System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; 
    加上这句就没问题了