I have a question concerning the comparison of ObservableCollections. Basically, in my scenario I have a business logic method that gets a set of items from database for current user in form of ObservableCollection. Periodically, a BackgroundWorker should get user items from DB using aforementioned method, compare them for changes and if any are detected it should trigger an update on UI. The problem is, even if no changes were done to data in DB, the ObservableCollections are always different.
Method used in BackgroundWorker:
private void UpdateItemList(object sender, DoWorkEventArgs e)
{
const int updateInterval = 30000;
while (isItemWorkerRunning)
{
Thread.Sleep(updateInterval);
Application.Current.Dispatcher.Invoke(() => ForceUpdateItemList());
}
}
private void ForceUpdateItemList()
{
var userItems = GetItems(userId);
if (lastUserItems!=userItems)
{
//force update
lastUserItems = userItems;
//update UI
}
}
What am I doing wrong?