private async void search_Click(object sender, RoutedEventArgs e) { List <Website> allSites = TheInternet.ReadFile(); var searchInput = Observable.FromEventPattern(this.textBox, "TextChanged") .Select(w => this.textBox.Text) .Where(n => n.Count() > 3) .Throttle(TimeSpan.FromSeconds(0.5)) .DistinctUntilChanged(); Tools.DebugTrace("ctor", Thread.CurrentThread.ManagedThreadId); Tools.DebugTrace(searchInput.ToString(), Thread.CurrentThread.ManagedThreadId); //var res = await Task.Run( () => SearchEngine.SearchWebSites(allSites, searchInput.ToString()) ); foreach (var site in allSites) { var res = await Task.Run(() => SearchEngine.Search(site, searchInput.ToString())); res.ToObservable() .ObserveOn(Dispatcher) .Select(x => x) .Subscribe(y => PopulateView(site, y)); } }
public async void TestStream() { for (int i = 100; i > 0; i--) { var res = await Task.Run(() => TheInternet.TestLongProcess(i)); var seq = res.ToObservable(); Debug.WriteLine($"Current thread Id b : {Thread.CurrentThread.ManagedThreadId}"); var ui = seq .ObserveOn(Dispatcher) .Select(x => x) .Take(90) .Subscribe(test => this.listView.Items.Add(test)); } }
public async void DisplayBulkHeadLines(WebsiteType type, int headlines) { int countSites = 0; List <Website> allSites = TheInternet.ReadFile(type); int totalSites = (allSites.Count() == 0) ? 1:allSites.Count(); if (this.listView.Items.Count > 0) { this.listView.Items.Clear(); } if (this.sitelistBox.Items.Count > 0) { this.sitelistBox.Items.Clear(); } PopulateSiteListbox(); foreach (var site in allSites) { Tools.DebugTrace("siteloop", Thread.CurrentThread.ManagedThreadId); countSites++; var data = await Task.Run(() => Downloader.DownloadHtml(site)); var listView = data.ToObservable() .ObserveOn(Dispatcher) .Where(x => x.Length > 5) .Select(x => x.Trim()) .Take(headlines) .Subscribe(x => PopulateView(site, x)); statusLabel = data.ToObservable() .ObserveOn(Dispatcher) .Subscribe(x => PopulateLabel($"From {site.SiteName} | Feteched {countSites} of {totalSites}")); } statusLabel.Dispose(); }
public void PopulateSiteListbox() { TheInternet.ReadFile().ForEach(site => this.sitelistBox.Items.Add(site.SiteName)); }