0
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Subscriber sub = new Subscriber();
        //sub.AddToSpeed();

        Thread th1 = new Thread(test1);
        th1.Start();
    }

    private void test1()
    {
        for (int i = 1; i < 10000; i++)
        {
            System.Diagnostics.Debug.WriteLine(i.ToString());
        }
        textBox1.Text = "test";
    }

}

I thought the above code should give me an error saying "invalid cross thread access" error as I am trying to update the text box from another thread. But it is note giving me an error. I want to understand why is it not giving me an error.

Update: If I press Ctrl + F5 and click on button works fine. If I just press F5 and click on button throws an error. Can any one explain please.

Virus
  • 3,215
  • 7
  • 29
  • 46

0 Answers0