So I have a block of code like
EventLog.WriteEntry("About to run the task");
// run the dequeued task
var task = PageRetrievals.Dequeue();
PageRetrieval retrieval = new PageRetrieval();
var continuation = task.ContinueWith(t => retrieval = t.Result);
task.Wait();
EventLog.WriteEntry("html = " + retrieval.Html.DocumentNode.OuterHtml);
where the WriteEntry
s are just my sanity-check that this is working. But the 2nd isn't getting called and I'm trying to figure out why my code isn't reaching that point.
The above block of code is inside a method that is
MyTimer.Elapsed += new ElapsedEventHandler(MethodThatInvokesTheAboveCode);
and the type of task is like
PageRetrievals.Enqueue(new Task<PageRetrieval>(() =>
new PageRetrieval()
{
Html = PageOpener.GetBoardPage(pagenum),
Page = PageType.Board,
Number = pagenum
}
));
where PageOpener.GetBoardPage
simply gets the HTML from a URL, like
private static HtmlDocument GetDocumentFromUrl(string url)
{
var webget = new HtmlWeb();
var doc = webget.Load(url);
return webget.StatusCode == System.Net.HttpStatusCode.OK ? doc : null;
}
public static HtmlDocument GetBoardPage(int pageNumber)
{
return GetDocumentFromUrl(string.Format(BoardPageUrlFormat, pageNumber));
}
Is there anything about this that looks obviously wrong?