Thread Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alive
    New Member
    • Jan 2012
    • 1

    Thread Not Working

    Can somone tell me why richtextbox text is not changing?

    Code:
    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Thread t = new Thread(rtb2);
                t.Start();
            }
    
            private void rtb2()
            {
                try
                {
                    richTextBox1.Text = "1";                
                }
                catch(InvalidOperationException ex)
                {
                    MessageBox.Show("HI");
                }            
            }
        }
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Can you be a bit more clear as to the problem you're getting? I would have expected an invoke exception, but your thread suggests it's just doing nothing?

    Can you please clarify and provide details about the problem?

    Thanks!

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      You need to utilize the TextChanged (http://bit.ly/z1XBEQ) event of the RichTextBox

      Comment

      Working...