Accessing win forms control throws exception from different thread only in Visual Studio
<p>My knowledge was that accessing UI control will throw exception if it is
accessed from the thread that is not the thread that created it (UI thread).</p>

<p>I got a code that does not throw exception when accessing simple properties
of the UI control when run in Visual Studio with debugger. </p>

<pre><code>            var name = comboBox1.Name;
            var m1 = comboBox1.Items[1].ToString();
</code></pre>

<p>It does when accessing SelectedIndex of the ComboBox.</p>

<pre><code>            comboBox1.SelectedItem.ToString();
</code></pre>

<p>The same code run without debugger does not throw exception?
The same behavior is when double clicking on the exe, no exception?</p>

<p>Why there is only exception when code is run with debugger attached and not
when running without debugger (Ctrl + F5) ?</p>

<pre><code>public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        comboBox1.Items.Add("one");
        comboBox1.Items.Add("two");
        comboBox1.Items.Add("three");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Task.Factory.StartNew(() =&gt;
        {
            var name = comboBox1.Name;
            var m1 = comboBox1.Items[1].ToString();

            MessageBox.Show(comboBox1.SelectedItem.ToString(), "MM");
        });
    }
}
</code></pre>