My App is .NET 4.5 and I have a event handler that logs all error on unobserved task exceptions.
TaskScheduler.UnobservedTaskException += (sender, e) => e.Exception.Handle(ex =>
{
logger.Error(e.Exception);
return false;
});
I return false, what shuts down the application. Simulating the .NET 4.0 behavior.
My question is, why this code calls the event and consequently crash my app if I am observing the result?
try
{
var resultado = httpClient.GetAsync('http://.....').Result;
}
catch (Exception ex)
{
logger.Error(ex);
}
UPDATE: After some debugging, I figure out that I had another Task when I didn´t called .Result and was causing the problem.
After some debugging, I figure out that I had another Task when I didn´t called .Result and was causing the problem.