This is how i call that error given function
var开发者_JAVA技巧 CrawlPage = Task.Factory.StartNew(() =>
{
return crawlPage(srNewCrawledUrl);
});
var GetLinks = CrawlPage.ContinueWith(resultTask =>
{
if (CrawlPage.Result == null)
{
return null;
}
else
{
return ReturnLinks(CrawlPage.Result, srNewCrawledUrl, srNewCrawledPageId);
}
});
This is the error i really don't understand how is that possible. I am using local assigned variables so variables should be thread safe for all threads. Am i incorrect ?
this is the error image :
you better validate InnerHtml is null or not before calling
var GetLinks = CrawlPage.ContinueWith(resultTask =>
{
if (CrawlPage.Result == null || CrawlPage.Result.DocumentNode == null || CrawlPage.Result.DocumentNode.InnerHtml == null)
{
return null;
}
else
{
return ReturnLinks(CrawlPage.Result, srNewCrawledUrl, srNewCrawledPageId);
}
});
Or check this on ReturnLinks method
I am using local assigned variables so variables should be thread safe for all threads. Am i incorrect ?
The fact that you are making a reference local does not mean that the object this reference points to suddenly becomes local. Other thread (not shown in your question?) might still be mutating the HtmlDocument
object at just the wrong moment (between hdDoc.DocumentNode != null
and hdDoc.DocumentNode.InnerHtml != null
).
精彩评论