This is just a curious question. Which one is the best way to update UI from another thread. First, this one:
private delegate void MyDelegateMethod();
void MyMethod()
{
if (unknowncontrol.InvokeRequired)
{
this.BeginInvoke(new MyDelegateMethod(MyMethod));
return;
}
unknowncontrol.property = "updating!";
}
On the other hand:
Invoke((System.Threading.ThreadStart)delegate()
{
unknowncontrol.property = "updating!";
});
Or, is there a better way to do this?
Of course this is for WinForms, for WPF there's the dispatcher. How is the code for WPF?
I'm asking, 'cause, in the past I experienced errors when updating UI from a raised event using both of the options above. The kind of error like: "there is no source code available". I assume all of us have seen them :D.
Thanks, and have a nice day!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…