ObservableCollectionsの比較に関する質問があります。基本的には、私のシナリオではObservableCollectionの形式で現在のユーザーのデータベースから項目のセットを取得するビジネスロジックメソッドがあります。定期的に、BackgroundWorkerは前述のメソッドを使用してDBからユーザーアイテムを取得し、変更を比較し、検出された場合はUIの更新をトリガーする必要があります。問題は、DB内のデータに変更が加えられていなくても、ObservableCollectionsは常に異なっていることです。 BackgroundWorkerのに使用される変更のObservableCollectionの比較
方法:
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
}
}
は私が間違って何をしているのですか?