This is just a curious question. Which one is the best way to update an interface from another thread. The first is:
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 is a dispatcher. How is the code for WPF?
I ask, because in the past I experienced errors when updating the user interface from the raised event, using both of the above options. Such an error as: "no source code." I guess we all saw them: D.
Thank you and have a nice day!
source share