Loading tableadapter in wpf asynchronously

168 Views Asked by At

I am trying to load a table adapter asynchronously. I used the await method.

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. and when I press the the combo Box to choose and ID the program locks up. When I debug the application, I get a "ContextSwitchDeadLock occurred". 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.

1

There are 1 best solutions below

0
Gisiota On

I got it to load by refreshing the viewsource.

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