At the moment I've got a strange release-only crash in my program. It seems to be throwing a NullReferenceException
on webPageLoader[i].Join();
but I doesn’t seem to fail in debug.
Could my problem be related to the fact that the thread has not had the chance to start so therefore can’t be joined? Has anyone got any tips to how I could go about debugging this as it doesn’t seem to manifest in debug at all.
If I put a sleep(50)
before webPageLoader[i].Join();
it doesn’t seem to crash. But I would expected it to not crash without the sleep
.
for (int i = 0; i < pagesToGet; i++)
{
crawlContext.vistedURLs.AddURL(CurrentURL);
document[i] = new DocumentToScrape();
webPageLoader[i] = new Thread(document[i].LoadPage);
webPageLoader[i].Start(CurrentURL);
if (!crawlContext.unVistedURLs.MoveNext())
{
break;
}
}
for (int i = 0; i < pagesToGet; i++)
{
**webPageLoader[i].Join();**
if (document[i].Doc != null)
{
document[i].Doc = GetSubSetXPath(document[i].Doc, crawlContext.xPath);
if (document[i].Doc != null)
{
crawlContext.scrapedUrls = ScrapeURLS(crawlContext.scrapedUrls, document[i]);
}
else
{
//System.Windows.Forms.MessageBox.Show("Null Page Found");
}
}
}