本文介绍了WPF BeginInvoke和EntityFramework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我通过数据库进行搜索.搜索在单独的线程中进行.找到实体后,我必须将其和一些相关数据显示到WPF UI中.

我使用EntityFramework.搜索过程的主要思想是:

Hi
I have a search through database. Search works in separate thread. When entity is found I have to show it and some of related data into WPF UI.

I use EntityFramework. Main idea of search process is:

foreach (var item in _currentEntitySet)
{
    Items.Add(item);
    OnItemFound(item);
}



其中_currentEntitySet是一个ObjectQuery

但是我遇到了一些问题.触发OnItemFound时,我尝试使用BeginInvoke()在UI中显示找到的项目和一些相关对象.



Where _currentEntitySet is an ObjectQuery

But I have met some problems. When OnItemFound is fired, I try to use BeginInvoke() to display found item and some related object in UI.

private void OnCatalogueItemFound(CatalogueItem item)
{
    Application.Current.Dispatcher.BeginInvoke(new Action<object>((param) =>
    {
        var model = new CatalogueResultItemViewModel(param as CatalogueItem);
        TitlesResultViewModel.Add(model);
    }), System.Windows.Threading.DispatcherPriority.Background, item);
}



问题在于项目的导航属性为NULL

当我使用Invoke()而不是BeginInvoke()时,一切正常.由于其他一些原因,我必须完全使用BeginInvoke().

有谁知道在我的情况下如何使用BeginInvoke()?谢谢:)



The problem is that navigation properties of item are NULL

When I use Invoke() instead of BeginInvoke() then things works fine. I have to use exactly BeginInvoke() because of some other reasons.

Does anyone knows how can I use BeginInvoke() in my situation? Thanks :)

推荐答案


这篇关于WPF BeginInvoke和EntityFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 10:15