Your understanding is correct. To see what's happening, I added some timing code:
Code:
Stopwatch textboxTiming, threadTiming;
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(DelegateProcedure));
t.Start();
}
private void DelegateProcedure()
{
Random random = new Random();
StringBuilder sb = new StringBuilder();
threadTiming = new Stopwatch();
threadTiming.Start();
for (int x = 0; x <= 50000; x++)
sb.Append(random.Next(0, 100));
threadTiming.Stop();
if (this.InvokeRequired) this.BeginInvoke(new Action<string>(SetOutputText),
new object[] { sb.ToString() });
}
private void SetOutputText(string s)
{
Stopwatch textboxTiming = new Stopwatch();
textboxTiming.Start();
textBox1.Text = s;
textboxTiming.Stop();
MessageBox.Show(string.Format("Spent {0} ms in thread, {1} ms in SetOutputText()", threadTiming.ElapsedMilliseconds, textboxTiming.ElapsedMilliseconds));
}
On my computer, the thread took 16 ms to execute, and setting the textbox text took over 2 seconds. That's why the main thread stalls - the longest portion of the execution is happening in that thread.