I have the following situation:
foreach(var item in collection)
{
DoWork().Wait;
}
As you can see there is a foreach that iterate over a collection, for each call I need to wait that DoWork
complete the execution, after that the foreach can continue.
The problem's that inside DoWork
I'm using Parallel
and I get an exception that "freeze" the program, in particular isn't displayed any exception, this is my implementation:
public async Task DoWork()
{
Try
{
Parallel.Invoke(
() => Foo(),
() => Foo2(),
() => Foo3());
}
catch(Exception e)
{
//No exception caught
}
}
I added inside Foo
methods a Console.WriteLine
such as:
public void Foo()
{
Console.WriteLine("foo 1");
}
inside the method Foo2
an exception is generated, but I cannot see which exception is, because I setted a breakpoint on catch
and this isn't firing.
What I did wrong?