Hi I am making my web scraping tool, and I need to have a recursive function in milliseconds to view offer availability. But I can't handle the stackoverflow exception because i keep calling the viewoffers() function. Please help :)
public void viewoffers(IWebDriver driver, string user, string pass)
{
Thread.Sleep(timespan);
try { int c = driver.WindowHandles.Count; }
catch { AbortThread(user); }
driver.Navigate().GoToUrl("https://as.realtrans.com/webtop/orders/offers/offer_order_viewInfo.asp?user=" + user);
try { int c = driver.WindowHandles.Count; }
catch { AbortThread(user); }
if (driver.Url.ToString().Contains("offer_order_viewInfo.asp?user="))
{
try { int c = driver.WindowHandles.Count; }
catch { AbortThread(user); }
if (driver.PageSource.Contains("id=\"chkOffer\""))
{
driver.FindElement(By.Id("chkOffer")).Click();
driver.FindElement(By.ClassName("CellClass")).FindElement(By.TagName("a")).Click();
driver.FindElement(By.Name("btnSubmit")).Click();
}
this.viewoffers(driver, user, pass);
}
else
{
this.reopenaccount(driver, user, pass);
}
}
public void AbortThread(string username)
{
RunningAccounts ra = runningAccounts.Find(item => item.account.username == username);
runningAccounts.Remove(ra);
threadsList.Remove(ra.thread);
ra.thread.Abort();
}
And it will just stop if I make close of the running thread in my program.