c# - Catel (MVVM framework) ObservableCollection -
i'm using catel implement wpf application.
i have class extends observablecollection
, every time item inserted ui must updated.
code (simplified version) :
public abstract class logcollections : observablecollection<log4netlog> { private readonly object _locker; protected logcollections() { _logchart = new logginglevelchart(); _locker = new object(); } public object locker { { return _locker; } protected override void insertitem(int index, log4netlog item) { lock (_locker) { base.insertitem(index, item); if (item == null) { return; } log4netlog temp = item log4netlog; // updating if (temp != null) { // updating } } //unlock } } }
until have used bindingoperations.enablecollectionsynchronization available in .net 4.5. unfortunately have compile code using .net 4.
i want know that, there in catel framework solves kind of problem.
more info:
for application performance main issue, since add many items collection.
update:
using fastobservablecollection
solves problem, ui freezes 5-7 sec out of using. guess that, caused dispatcher
i have manually overridden oncollectionchanged
:
protected override void oncollectionchanged(notifycollectionchangedeventargs e) { dispatcherhelper.currentdispatcher.begininvoke(new action(() => base.oncollectionchanged(e)), dispatcherpriority.contextidle); }
this not solution. there better way avoid problem?
you might consider using fastobservablecollection in catel:
using (fastcollection.suspendchangenotifications()) { // todo: add , remove items here }
as out of using, pass it's change notifications
to around threading issues, can use dispatcherhelper.