Hi Guys, I am having some difficulty with a SQL Query using LINQ.
Application Overview: I am trying to put together an application for displaying my Movie Collection. In the Application, i have a ListBox that is populated with images, the URL's to those images are stored in an SQL Server Table.
When i run the below code to fetch the Information including the URL, the Images are eventually displayed. However, the query locks up the application UI until completion of the query and population of the ListBox with the Images.
var query = from s in dc.movies
orderby s.movie_NAME ascending
select s;
MovieListBox.ItemsSource = query.ToList();
Question: Is there a way to add large items to a ListBox without clogging the application UI?
More Information: I am pretty sure the below code will run the query in a seperated thread but i don't think that is the problem. I think the issue is with adding such a large amount of images to the ListBox at once.
Maybe adding the Images one by one could be a solution?
public void LoadMovies()
{
Thread thread = new Thread(ThreadLoadMovies);
thread.Start();
}
private void ThreadLoadMovies()
{
var query = from s in dc.movies
orderby s.movie_NAME ascending
select s;
MovieListBox.Dispatcher.Invoke(new Action(() => MovieListBox.ItemsSource = query.ToList()), DispatcherPriority.Normal, null);
}
I just read the question and i understand how vague it is and apologise for that, i can't think of a better way of writing it.
Thanks for your help in advance,
Alex