But you want to notify the user when the process is done. Trouble is, since the background process is running in a different thread from the user interface, the process crashes if you make any attempt to update the user interface directly.
Here's some sample code to solve this with the Dispatcher--kind of well known, but nice to document anyhow:
void UpdateText(string text)
{
if (this.Dispatcher != System.Windows.Threading.Dispatcher.CurrentDispatcher)
{
this.Dispatcher.Invoke(new Action
}
else
{
this.sampleTextBox.Text = text;
}
}
More common solution is probably to use a delegate as member of class that creates thread. ;-)
ReplyDeleteThat's basically what is being done in that initial post. Nothing different than your comment.
ReplyDelete