MVVM Project update and some ICollectionView weirdness

MVVM Project Update
Aside from the fact that it took me 10 minutes to find a way to log into my blogger account and post this...my MVVM side project is going pretty well.

For those of you who want a sneak peak, go here.  It even works to some degree (seriously!).  Of course, it's a tool that is only relevant to developers such as myself, but hey, it's something.

It is (going to be) a source control monitoring program that will give you nice little tray popups for any new commits on any repos you are monitoring.  Right now, it is only functional with SVN, but it will be readily extensible.  And the tray popups aren't there yet, either...but you can view history and even diff changes in the main window.

ICollectionView Problem
One tidbit I wanted to share here was something I learned about the ICollectionView.  This interface is extremely handy to watch collection changes initiated by a user in your viewmodel and I've used it a bunch of other places...but not quite like I did for this project.

Each Repository object in my project creates it's own exposed ICollectionView property that it maintains...which keeps the complexity of managing repository histories down in the Repository itself.  Each Repository object is initialized on a background thread, including the creation of its ICollectionView CommitItems property.

This lead to some serious head scratching as I encountered a 'NotSupportedException'.  As I began investigating this, I stumbled across this post which pointed me to the root cause lying in the fact that the ICollectionView object must be updated and initialized on the same (preferrably UI) thread.  

If an ICollectionView is, say, initialized on a background thread, then updated on a UI thread with the spiffy code I found on that blog, the View is never updated, even though you will no longer get an exception.  However, if it is initialized on the UI thread, all updates (on the UI thread) notify the View correctly.  Inherently, the ListCollectionView (the DefaultView for the CollectionViewSource) hangs onto the thread that it was created on for updates.  

Most of the time, this is very handy since (generally) this object is created in the ViewModel which is usually also created on the UI thread.  But not this time...

Just thought I'd share!  I'm probably ready to dig into MVVM with my project, but I'm want to tack on a few more features first...more to come!

Comments

Popular posts from this blog

35x Improved T-SQL LevenShtein Distance Algorithm...at a cost

The hidden workings of __doPostBack - Full or Partial Postback?

Facing Death...dum de dum dum