I am setting the .Text value of a textbox, disabling it, and then calling a BackgroundWorker to do a lengthy filesystem operation. The textbox does not update with the new text value until about halfway through the BackgroundWorker operation.
What can I do to force the texbox to show the new text value ASAP? Relevant code below:
void BeginCacheCandidates()
{
textBox1.Text = "Indexing..."; // <-- this does not update until about 20 to 30 seconds later
textBox1.Enabled = false;
backgroundWorker1.RunWorkerAsync();
}
void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
//prime the cache
CacheCandidates(candidatesCacheFileName);
}
void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
textBox1.Text = "";
textBox1.Enabled = true;
textBox1.Focus();
}
Update: I resolved the issue. It was code unrelated to this – I had overridden WndProc and it was going into a loop…
Unless there’s some detail I’m missing, wouldn’t ReportProgress give you what you want?