1

Recently, I tried to use multithreading in winform, and I copied a piece of code online. Unexpectedly, this code runs normally on my computer, and there is no cross-thread access exception. I want to figure out why. I use the .net4.0 csc compiler to build the program, win7 ultimate sp1. My particle code is as follows

public void button_1Click(object sender,EventArgs e)
{
    Thread t = new Thread(calc);
    t.Start();
}
public void calc()
{
    string text ="";
    for(i=1;i<=1000000;i++)
    {text += i.ToString();}
    this.textbox_1.Text = text;
}
MikeStrong
  • 11
  • 1
  • What is `textbox_1`? – TimTIM Wong Aug 07 '20 at 01:07
  • You can either take the risk or not, not every call will throw an Cross-thread operation not valid exception all the time, some may never throw, its as simple as that. Do you feel lucky, how much do you like your end user? – TheGeneral Aug 07 '20 at 01:10
  • 2
    Duplicate of: [Why can I access controls from a form in a thread without cross thread exception?](https://stackoverflow.com/questions/14580766/why-can-i-access-controls-from-a-form-in-a-thread-without-cross-thread-exception) and: [Expected cross-thread exception in a C# WinForms application did not occur](https://stackoverflow.com/q/36860555/8967612) – 41686d6564 stands w. Palestine Aug 07 '20 at 01:13

0 Answers0