I have an asynchronous task that is conditional. I want to await it if it's called, but, obviously, not wait for it if it's not.
This is what I tried.
Task l;
if(condition)
{
l = MyProcessAsync();
}
//do other stuff here
if(condition)
{
await Task.WhenAll(l); //unassigned variable error
}
I get Use of unassigned local variable 'l'
compiler error.
What's the appropriate way to do this?