I have been playing around with the new async CTP and MVVM patterns. I have been converting an old program of mine that was using a background worker and report progress to update a collection in my model. I have converted it to something like so

Calling it like this from some method run on the UI thread, like an event handler:

f();

works exactly as it should. It executes the first iteration of the cycle and then returns. The next iteration is executed after 500 ms (or more, if the UI thread is busy) on the UI thread.

On the other hand, if you call it like this:

Task.Run(addNames);

it doesn't work correctly. The reason for this is that async methods try to continue in the same context as they were started (unless you explicitly specify otherwise). The first version was started on the UI thread, so it continued on the UI thread. The second version started on a ThreadPool thread (thanks to Task.Run()) and continued there too. Which is why it caused your error.

While it is true that you aren't able to update an ObservableCollection from a second thread, it is possible to create an asynchronous observable collection. This allows you to update the collection from within tasks, or on threads where the collection wasn't created.

I would post the example, but I found the information here. It's pretty slick, and I found it to be a very helpful example.