This async method generates two CS0165 errors - Use of unassigned local variable.
public async Task<Tuple<bool, string>> DoWorkAsync(object[] objs)
{
string msg;
bool result;
await Task.Run(() => result = _foo.DoWork(objs, out msg));
return new Tuple<bool, string>(result, msg);
}
Initially I was going to ask why, but now I'm pretty sure it's because an exception may be raised within the local Task.
See magician Jon Skeet's comment below: the compiler doesn't know what Task.Run is doing, and cannot infer that the locals will be assigned.
So now I'll ask: what's the best way to implement this? Assign default values to the locals, create a local for the task and check task.IsFaulted before returning?
Should I generally propagate the exception? I suppose that's probably an unanswerable question depending on the context.