Galera,
I'm implementing a code to download pdf's from a particular site.
Debugging it, I discovered that the tasks were asynchronous and the counter was lost and it ended up getting some page without downloading.
I changed the process to a task around the clock (task.RunSynchronously).
Following code:
while (numeroPagina <= qtdePaginas){
var task = new Task<long>(() => {
paginaCarregada = false;
urlPesquisa = urlPesquisaOriginal;
urlPesquisa = urlPesquisa.Replace("datatrocar", dataFiltro);
urlPesquisa = urlPesquisa.Replace("first", numeroPagina.ToString());
wbDO.Navigate(urlPesquisa);
return numeroPagina++;
});
task.RunSynchronously();
}
However, I have not received the wbDO_DocumentCompleted event that downloads the sample itself:
private void wbDO_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string pagina;
pagina = wbDO.Document.Body.Parent.OuterHtml;
if (download)
{
DownloadDocumentos(wbDO.Document.Body.Parent.OuterHtml);
}
else
PesquisarData();
}
Could you help me understand what happened?