Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Conversation

kernel32uiuc
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant