Платформа: WPF, .NET 4.0, C# 4.0
Проблема: в Mainwindow.xaml у меня есть ListBox, связанный с коллекцией Customer, которая в настоящее время является ObservableCollection < Клиент > .
ObservableCollection<Customer> c = new ObservableCollection<Customer>();
Эта коллекция может быть обновлена через несколько источников, таких как FileSystem, WebService и т.д.
Чтобы разрешить параллельную загрузку Клиентов, я создал вспомогательный класс
public class CustomerManager(ref ObsevableCollection<Customer> cust)
который внутренне порождает новую задачу (из библиотеки параллельных расширений) для каждого клиента Source и добавляет новый экземпляр клиента к объекту коллекции клиента (передан ref в его ctor).
Проблема заключается в том, что ObservableCollection <T> (или любая коллекция, если на то пошло) не может использоваться из вызовов, отличных от потока пользовательского интерфейса, и возникает исключение:
"NotSupportedException - этот тип CollectionView не поддерживает изменения в SourceCollection из потока, отличного от потока Dispatcher."
Я попытался использовать
System.Collections.Concurrent.ConcurrentBag<Customer>
но он не реализует интерфейс INotifyCollectionChanged. Поэтому мой интерфейс WPF не будет автоматически обновляться.
Итак, существует ли класс коллекции, который реализует уведомления об изменении свойств/коллекции, а также позволяет звонить из других потоков, отличных от UI?
По моему первоначальному bing/googling, из него ничего не предоставляется.
Изменить: я создал свою собственную коллекцию, которая наследуется от ConcurrentBag < Клиент > , а также реализует интерфейс INotifyCollectionChanged. Но, к моему удивлению, даже после вызова его в отдельных задачах, пользовательский интерфейс WPF зависает, пока задача не будет завершена. Не выполняются ли задачи, которые должны выполняться параллельно, а не блокировать поток пользовательского интерфейса?
Спасибо за любые предложения, заранее.