You need to look at marshalling between your worker thread and the UI thread. The way your example would work is that the
richtext
will fill on the UI thread anyway. Granted, the updates of the
richtext
need to occur on the UI thread, but not the work of getting the data (the for loop). And finally, the setting of the
picturebox
's visible property needs to be marshalled back to the UI thread also.
Your huge method then becomes something like:
for (int i = 0; i < 10000; ++i) {
if (richTextBox1.InvokeRequired) {
richTextBox1.BeginInvoke((MethodInvoker) delegate { richTextBox1.Text = richTextBox1.Text + "s"; });
}
}
You'd probably want to speed up the action on the UI thread of appending the "s" to the RichTextbox as well. Get the initial value of the text at the start of huge(), append "s" to that on each loop, and then your delegate becomes
{ richTextBox1.Text = text; }
.
The less work you can do on the UI, the more responsive it will become.