public List<string> ShowAllBooks() { List<string> booksList = new List<string>(); try { using (bookcatalogueEntities context = new bookcatalogueEntities()) { // Fetch the product number of every product in the database var books = from b in context.catalagues select b.Title; booksList = books.ToList(); } } catch { // Ignore exceptions in this implementation } // Return the list of product numbers return booksList; } }
private void ShowAllBooks() { CatalogueManagerClient.ServiceReference.BookCatalogueServiceClient proxy = new BookCatalogueServiceClient(); try { lbBooks.Dispatcher.Invoke(new Action(() => { lbBooks.ItemsSource = proxy.ShowAllBooks(); }), DispatcherPriority.ApplicationIdle); //books = App.BookCatalogue.GetBook(query); //lbBooks.ItemsSource = books; txtBookPath.Foreground = Brushes.Black; txtBookPath.Text = "Ready"; } catch (CommunicationException ex) { MessageBox.Show(proxy.State.ToString() + " ..."+ex.Message); } }
<ListBox Height="440" KeyDown="lbBooks_KeyDown" MouseDoubleClick="lbBooks_MouseDoubleClick" Name="lbBooks" SelectionChanged="lbBooks_SelectionChanged" Width="210" />
try { booksList.Clear(); // rest of the code.. .. .. .. .. .. .. }
private void ShowAllBooks() { System.Threading.Task.Factory.StartNew(()=>{ CatalogueManagerClient.ServiceReference.BookCatalogueServiceClient proxy = new BookCatalogueServiceClient(); try { lbBooks.Dispatcher.Invoke(new Action(() => { //this will workaround your issue var serviceBooks= proxy.ShowAllBooks(); lbBooks.ItemsSource = serviceBooks; }), DispatcherPriority.ApplicationIdle); //books = App.BookCatalogue.GetBook(query); //lbBooks.ItemsSource = books; txtBookPath.Foreground = Brushes.Black; txtBookPath.Text = "Ready"; } catch (CommunicationException ex) { MessageBox.Show(proxy.State.ToString() + " ..."+ex.Message); } }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)