xamarin / app-crm

MIT License
387 stars 249 forks source link

Awaiting the inner task instead of outer task #111

Open kernel32uiuc opened 7 years ago

kernel32uiuc commented 7 years ago

Task.Factory.StartNew returns a nested task (Task). Awaiting a nested task is dangerous:

If DeAuthenticate() call returns false, an exception in line 63 will be thrown to the inner task. The exceptions in a task can only propagate to the caller if the task is awaited or waited. In line 58, only the outer task is awaited so the exceptions in the inner task will be swallowed and have no effect at all: the user will never see the “DeAuthenticate” error and the developer cannot handle this exception.

That's why, we should always unwrap the nested task (with Unwrap() or using Task.Run) and await the inner task.