public void AddProduct(Product product) { Task.Run(async() => { await productsService.AddProductToDatabase(product); var products = await productsService.GetProducts(); Products = new ObservableRangeCollection <Product>(products); //DispatcherHelper.CheckBeginInvokeOnUI(() => //{ // Products = new ObservableRangeCollection<Product>(products); //}); }); }
public async Task AddProduct(Product product) { try { await productsService.AddProductToDatabase(product); } catch (Exception ex) { Console.WriteLine(ex.Message); } var products = await productsService.GetProducts(); Products = new ObservableCollection <Product>(products); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Products = new ObservableCollection <Product>(products); }); }