I\'ve been learning to use TPL and have an issue with an example I gathered from this article. I copy and pasted the code exactly as in the Task.Run example but get an error
As mentioned in Stephen's correct answer this happens only when the Debugger is on. Using this simple workaround you can re-throw the exception "outside" of Task.Run();
Exception exceptionOut = null;
await Task.Run(() =>
{
try
{
// Your code
}
catch (Exception exceptionIn)
{
exceptionOut = exceptionIn;
}
});
if (exceptionOut != null)
throw exceptionOut;