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.
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.