when we try to update UI elements from a different thread in Silver light ( asynchronous callbacks such as xml, json, WCF), we will run into invalid cross-thread access error if a “Dispatcher.BeginInvoke” is not used.
In most cases we can use the following and it will work fine.
this.Dispatcher.BeginInvoke(delegate()
{
//do something here
});
However, this won’t work on static functions/methods, because for the most obvious reason, “this” can not be used in static function.
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
//do something here
});
System.Windows.Deployment.Current.Dispatcher.BeginInvoke should always be used to avoid invalid cross-thread access error.
Copied from:- http://mostup.com/2010/05/14/silverlight-invalid-cross-thread-access/
In most cases we can use the following and it will work fine.
this.Dispatcher.BeginInvoke(delegate()
{
//do something here
});
However, this won’t work on static functions/methods, because for the most obvious reason, “this” can not be used in static function.
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
//do something here
});
System.Windows.Deployment.Current.Dispatcher.BeginInvoke should always be used to avoid invalid cross-thread access error.
Copied from:- http://mostup.com/2010/05/14/silverlight-invalid-cross-thread-access/
No comments:
Post a Comment