I find it works best to treat data-bound items as though they were part of the UI. So, nothing that is data-bound should be accessed from a background thread.
Ideally, your database access would be using something like EF6 which supports asynchronous methods. However, since you do not have an async
database layer, you can use a "fake asynchronous" approach to push the (synchronous) database work onto a background thread:
public async Task RefreshItemsAsync()
{
IsRefreshing = true;
var items = await Task.Run(() => _db.GetItems());
var itemsCollectionView = CollectionViewSource
.GetDefaultView(new ObservableCollection<ItemType>(items));
Items = itemsCollectionView;
IsRefreshing = false;
}
private async Task DeleteAsync(ItemType item)
{
await Task.Run(() => _db.DeleteItem(item));
var items = (ObservableCollection<ItemType>)Items.SourceCollection;
items.Remove(item);
}
However, this does require your database layer to be thread-agnostic. If it's caching some db connection or something that is tied to a specific thread then this approach won't work.