편집 : VS2008, .NET 3.5을 사용하고 있습니다.스레딩과 함께 DataView에서 RowFilter를 올바르게 사용 했습니까?
데이터 뷰에 채워지고 CollectionView로 전달되는 DataTable이 있습니다.
DataTable newLeadTable = new DataTable();
myConnection.Open();
dbAdpater.Fill(newLeadTable);
this.LeadDataView = new DataView(newLeadTable);
this.LeadsCollectionView =
CollectionViewSource.GetDefaultView(this.LeadDataView);
그 다음 데이터를 표시하는 데 사용하는 데이터 그리드보기에 필터 텍스트를 입력하는 사용자 후
this.LeadsCollectionView
에 결합되고, 뷰 모델은 DataView를에 필터 문자열을 설정하기 위해이 방법을 실행한다 :
private void SetLeadListFilter(string LeadFilterStr)
{
this.LeadDataView.RowFilter = filterString;
}
정상적으로 작동하며 DataGrid가 적절한 필터링 된 DataRow를 보여줍니다.
그런데 바쁜 표시기를 추가하여 UI 체험을하고 싶습니다. 그래서 나는 스레드에 위의 코드를 넣어 :
this.IsBusy = true;
Thread filterDataThread= new Thread(new ThreadStart(() =>
{
this.LeadDataView.RowFilter = filterString;
this.IsBusy = false;
}));
filterDataThread.Start();
지금은 이상하다, 나는 코드가 실행 된 필터가 잘 살고되는 것을 볼 수 있습니다. 그러나 DataGrid는 행을 필터링하지 않습니다!
그래서 지금은, 방법을 수정할 다시 CollectionView에 DataView를 재 할당 :
this.IsBusy = true;
Thread filterDataThread= new Thread(new ThreadStart(() =>
{
this.LeadDataView.RowFilter = filterString;
this.LeadsCollectionView = CollectionViewSource.GetDefaultView(this.LeadDataView); //Added this
this.IsBusy = false;
}));
filterDataThread.Start();
는 이제 작동! 데이터가 DataGrid에서 올바르게 필터링되고 있습니다!
그렇다면 스레딩을 사용할 때 왜 이런 일이 발생합니까? 이것이 스레딩에서 DataFilter를 사용하는 적절한 방법입니까? 내가 이해 한대로