TextBox and Thread

Posted by gloris on Stack Overflow See other posts from Stack Overflow or by gloris
Published on 2010-03-29T20:15:59Z Indexed on 2010/03/29 20:23 UTC
Read the original article Hit count: 294

Filed under:
|

Why doesn't this work?
The program stops on: this.textBox1.Text = "(New text)";

 Thread demoThread;
        private void Form1_Load(object sender, EventArgs e)
    {
        this.demoThread = new Thread(new ThreadStart(this.ThreadProcUnsafe));
        this.demoThread.Start();

        textBox1.Text = "Written by the main thread.";
    }

    private void ThreadProcUnsafe()
    {
        while (true)
        {
            Thread.Sleep(2000);

            this.textBox1.Text = "(New text)";           
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about textbox