The method StaticReports.AreaData that is within the Task below is returning an exception already handled in the method itself, the problem is that the Task continues execution of the next line var links = ListLists.ListLinksDownlaod (driver); that depends on the OpenDataAnal method to execute, so it also throws an exception. I have tried to handle the method, put the task inside a Try / catch, but nothing works, there is always the exception in the ListLinksDownlaod method and it should not even get there.
How can I stop the execution of the task, such as when we send a CancellationToken, but this time, when any exception occurs.
private async Task<List<IWebElement>> Acessar(IWebDriver driver, string data, CancellationToken ct)
{
return await Task.Run(() =>
{
ct.ThrowIfCancellationRequested();
LoginNgin.Login(config.User, config.Password, driver);
RelatoriosEstaticos.AbrirRelatoriosEstaticos(driver);
RelatoriosEstaticos.AbrirDataAtual(driver, data);
var links = ListArquivos.ListaLinksDownlaod(driver);
MethodInvoker action = delegate { pgbStatus.Maximum = links.Count(); };
pgbStatus.BeginInvoke(action);
return links;
});
}