6
The documentation of this method says:
Method Task.Yield() - adapted from English
Creates a task suitable which returns asynchronously to the current context when awaited.
I read the his source code and got lost even more!
public static YieldAwaitable Yield()
{
return new YieldAwaitable();
}
The class YieldAwaitable
is described this way: provides a context suitable to switch to a target environment (provides an awaitable context for switching into a target Environment).
I don’t understand the real use of it.
What does this function actually do? In what contexts would this method bring advantages and why?
This question concerns the method Task.Yield
and not the keyword yield
.
I did some translations on this question which may not be very good. Edits will be welcome. (1) I do not know if long-awaited would replace 100% of the word awaitable, so I brought the spelling.
Possible duplicate of What is the use of the reserved word "Yield"?
– Gabriel Coletta
yield
is a keyword used in iterators. My question completely differs. It is a method ofSystem.Threading.Tasks
.– vinibrsl