private void SearchLocationList(SearchInfo siSearch) { // Search each location in the list and append the results to our output HTML document // siSearch.HTMLSearchResults = ""; siSearch.HTMLSearchResults += "<table width=\"100%\">\r\n"; foreach (LocationInfo liLocation in siSearch.Locations) { // Get the search result list for this location // ++siSearch.CurrentLocationNumber; siSearch.CurrentLocationName = liLocation.State.ToUpper() + ": " + liLocation.City.ToUpper(); ArrayList alResults = SearchLocation(liLocation); // Stop if the user has requested us to do so // if (m_bUserStopRequested) break; // Stop if we are having connection issues after multiple attempts (this is set in SearchLocation()) // if (m_bConnectionTimeoutError) break; // If no results were found at this location, skip the output logic. // if (alResults.Count == 0) continue; // Output the city/state/result count header for this location // siSearch.HTMLSearchResults += "<tr><td colspan=\"2\"><h4 class=\"ban\" style=\"text-align:left;\"><a href=\"" + liLocation.URL + "\" target=\"_blank\">" + liLocation.State.ToUpper() + ": " + liLocation.City.ToUpper() + "</a>: " + alResults.Count.ToString() + " item(s)</h4></td></tr>\r\n"; // Output the result lines // foreach (SearchResultInfo srResult in alResults) { siSearch.HTMLSearchResults += "<tr>"; siSearch.HTMLSearchResults += "<td width=\"5%\" nowrap>" + srResult.Date + "</td>"; siSearch.HTMLSearchResults += "<td><a href=\"" + srResult.URL + "\" target=\"_blank\">" + srResult.Title + "</a></td>"; siSearch.HTMLSearchResults += "</tr>\r\n"; ++siSearch.ResultCount; } siSearch.HTMLSearchResults += "<tr><td> </td><td> </td></tr>\r\n"; } siSearch.HTMLSearchResults += "</table>\r\n"; // Signal to the UI thread that we're done // siSearch.SearchCompleted = true; }
private void menuSearchStart_Clicked(object sender, EventArgs e) { // Display the config dialog and let the user set up the search parameters // ConfigDialog dlgConfig = new ConfigDialog(m_alAllLocations, m_alAllCategories, m_alAllSubcategories); DialogResult drResult = dlgConfig.ShowDialog(); if (drResult == DialogResult.Cancel) return; // Set up variables used to communicate with the search threads // m_bSearchInProgress = true; m_bConnectionTimeoutError = false; m_bSearchCompleted = false; m_bUserStopRequested = false; m_sHTMLSearchResults = ""; EnableMenuItems(); // We will start multiple search threads here and assign each one to its own range of the location list // int iMaxLocationsPerThread = m_alAllLocations.Count / m_iMaxThreads; int iLocationIndexAll = 0; for (int iThreadIndex = 0; iThreadIndex < m_iMaxThreads; iThreadIndex++) { m_asiSearchList[iThreadIndex] = new SearchInfo(); for (int i = 0; i < iMaxLocationsPerThread; i++) { if (iLocationIndexAll < m_alAllLocations.Count) m_asiSearchList[iThreadIndex].Locations.Add(m_alAllLocations[iLocationIndexAll++]); } Thread thread = new Thread(StartSearchThread); thread.Start(m_asiSearchList[iThreadIndex]); } }