I have the following method in a base class that implements System.ComponentModel.INotifyPropertyChanged:
protected virtual void RaisePropertyChangedEventSynchronous(string propertyName) { try { if (PropertyChanged != null) { Delegate[] delegates = this.PropertyChanged.GetInvocationList(); foreach (PropertyChangedEventHandler handler in delegates) { try { DispatcherObject dispatcherInvoker = handler.Target as DispatcherObject; if (dispatcherInvoker != null) { dispatcherInvoker.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { handler(this, new PropertyChangedEventArgs(propertyName)); })); } else { handler(this, new PropertyChangedEventArgs(propertyName)); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionHandlingPolicyNames.LogPolicy); } } } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionHandlingPolicyNames.LogPolicy); } }
Sometimes I get the following exception registered in the file:
Type: System.InvalidOperationException, mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 Message: This operation cannot be completed while dispatcher processing is paused. Source: WindowsBase Reference link: Data: System.Collections.ListDictionaryInternal TargetSite: Void PushFrame (System.Windows.Threading.DispatcherFrame) Stack trace: in System.Windows.Threading.Dispatcher.PushFrame (DispatcherFrame) in System.Windows.Threading .DispatcherOperation.Wait (TimeSpan timeout) in System.Windows.Threading.Dispatcher.InvokeImpl (DispatcherPriority priority, TimeSpan timeout, delegation method, object arguments, logical isSingleParameter) in System.Windows.Threading.Dispatcher.Invoke (priority DispatcherPriority, Delegate method) in OCC600.Infrastructure.Dictionary.BusinessEntities.Observable.RaisePropertyChangedEventSynchronous (String propertyName)
If I use Dispatcher.BeginInvoke to update the user interface, I do not get these exceptions. But I found that performing updates using BeginInvoke is not reliable, because sometimes these changes do not affect the user interface.
How can I solve this problem?
Klaus nji
source share