0

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.

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
Gisiota
  • 343
  • 3
  • 4
  • 12
  • I gave a shot at your code, loaded the combo with 31,000+ IDs from DB with no problem loading or selecting it. Except that i did not do the `FindResource()` bit of it... May i ask what is that for? – jsanalytics Oct 14 '15 at 15:40
  • its just so I can move to the first record when its done loading. otherwise everything is blank. Thanks for trying it, did you use the same async methods? – Gisiota Oct 14 '15 at 16:15
  • For moving to the first record just do `SelectedIndex="0"` in your combo's XAML. If you get rid of the `FindResource()` bit does the problem go away? And yes, i used `async/await` for loading data. – jsanalytics Oct 14 '15 at 16:33
  • Interesting, well I removed the FindResource() like you suggested. it seemed to work but then I notice it happens again after I click on it again. So it allows me to choose an item from the combo box once, but then if I go ahead and try to choose another one it locks up. this is hard to debug too, since all the code runs fine. – Gisiota Oct 14 '15 at 18:03
  • Please post a stack trace, if you can get it. – jsanalytics Oct 14 '15 at 18:12
  • You also use `FindResource()` to assign your `comercialDataSet`... why? That seems unnecessary at best. – jsanalytics Oct 14 '15 at 18:21
  • These calls to `FindResource()` don't resemble anything close to a `MVVM` pattern.... I'm just trying to figure out if you have any reason for doing so that I'm not aware of. – jsanalytics Oct 14 '15 at 18:39
  • The FindResources() is something the compiler generates when you drop a dataset tool onto the form. It can be removed, but the problem still persists. Not really sure how to get a call stack, since the code does execute, so not really sure where to put the break-point. Thanks for your help. – Gisiota Oct 15 '15 at 11:17
  • I did notice, the combobox eventually does open with the results, but it takes a ridiculous amount of time to open (like 5-10 minutes). If I load my code synchronously, this problem does not happen. – Gisiota Oct 15 '15 at 11:18

1 Answers1

0

I got it to load by refreshing the viewsource.

((System.Windows.Data.CollectionViewSource)(this.FindResource("ViewSource"))).View.Refresh();
Gisiota
  • 343
  • 3
  • 4
  • 12