I would like to wait all task, but some of them can be null. It is a code like that:
Task<MyType1> myTask1 = getData01Async();
Task<MyTyp2> myTask2 = null;
Task<MyType3> myTask3 = null;
if(myVariable == true)
{
myTask2 = getData02Async();
}
else
{
myTask3 = getData03Async();
}
wait Task.WhenAll(myTask1, myTask2, myTask3);
The idea is, task1 always exists, but task2 and task3 depends of a variable. So I would like to run all the task in parallel and wait when all of them are finished. And if one task is null, the treat it as it is finished.
The problem with this code is that I get a null reference exception when it runs.
There are some way to do that? Or what another alternatives could I use?