简体   繁体   English

在WPF中异步加载tableadapter

[英]Loading tableadapter in wpf asynchronously

I am trying to load a table adapter asynchronously . 我正在尝试asynchronously加载表适配器。 I used the await method. 我使用了await方法。

Xaml: Xaml:

<ComboBox x:Name="IDComboBox" Grid.Column="1" DisplayMemberPath="ID" HorizontalAlignment="Left" Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="120"   Background="White" IsEditable="True" >
            <ComboBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </ComboBox.ItemsPanel>
        </ComboBox>

Code: 码:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
        loadData();
}
private async void loadData()
{
        // Load data into the table TBLPOOL. You can modify this code as needed.
        commercialDataSet = ((Cobra.CommercialDataSet)(this.FindResource("commercialDataSet")));


        var loadTblPool = Task<int>.Factory.StartNew(() => commercialDataSetTBLPOOLTableAdapter.Fill(commercialDataSet.TBLPOOL));
        await loadTblPool;
        tBLPOOLViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tBLPOOLViewSource")));
        tBLPOOLViewSource.View.MoveCurrentToFirst();

}

the above does load the data async, but the problem is I have a ID field in a combo-box. 以上确实加载了异步数据,但问题是我在组合框中有一个ID字段。 and when I press the the combo Box to choose and ID the program locks up. 当我按组合框选择ID时,程序将锁定。 When I debug the application, I get a "ContextSwitchDeadLock occurred". 当我调试应用程序时,出现“ ContextSwitchDeadLock发生”。 I looked that error up, and apparently it happens when a process is taking too long. 我查了一下这个错误,显然当一个过程花费太长时间时就会​​发生。 not sure why this is happening. 不知道为什么会这样。 If I don't load the data async, the combo-box works just fine. 如果我不异步加载数据,则组合框可以正常工作。

我通过刷新视图源来加载它。

((System.Windows.Data.CollectionViewSource)(this.FindResource("ViewSource"))).View.Refresh();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM