private void SearchWorkerDoWork(object sender, DoWorkEventArgs e) { ProductSearchResult result = null; try { var productName = (string)e.Argument; using (var harness = new ProductRepositoryHarness(_repo)) { result = harness.Search(productName); } } catch (Exception ex) { Log.Error("SearchWorkerDoWork - Error.", ex); result = new ProductSearchResult(false, true, null); } finally { if (((BackgroundWorker)sender).CancellationPending) e.Cancel = true; e.Result = result; } }
private void ProductSearchManagerResultsRecieved(ProductSearchResult result) { if (result.HasError) { ErrorMessage = SearchResultRetrievalError; } else if (result.Product == null) { ErrorMessage = NoResults; } else { try { ErrorMessage = string.Empty; ProductPrice = decimal.Parse(result.Product.SalePrice); ProductImage = SetProductImage(result.Product.imageUrl); } catch { ErrorMessage = SearchResultDisplayError; } } IsSearching = false; RefreshUi(); }