views:

12

answers:

1

Hi All,

I am creating a search page for books. There are lacks of data in the database. If the data size is more than 2000 the application is getting hanged. ItemsSource of the listbox having the data but something wrong is happening behind.

Code

 <ListBox Grid.Column="1" x:Name="lbResult"  ItemsSource="{Binding}" SelectionChanged="lbResult_SelectionChanged">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Width="320">
                                            <TextBlock Margin="10"><InlineUIContainer>
                                            <TextBlock Foreground="DarkKhaki" Text="{Binding Title}"/>
                                        </InlineUIContainer><Run Text=" "/><LineBreak/><InlineUIContainer>
                                            <TextBlock Text=" By "/>
                                        </InlineUIContainer><Run Text=" "/><InlineUIContainer>
                                            <TextBlock Text="{Binding Author}"/> 
                                        </InlineUIContainer></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                                <ListBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel IsItemsHost="True" Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ListBox.ItemsPanel>
                            </ListBox>
A: 

The application is apparently "hanging" because the data load is happening on the UI thread.

You should consider a different model that enables you to load the data in another thread and update the UI periodically or as and when new data arrives.

You can use an ObservableCollection for this.

The background loading thread updates the collection and this fires an event out to the UI thread indicating that an update is required.

There's an example of how to do this on GALA Soft (I'll try an extract the relevant bit for inclusion here)

ChrisF