The returned ValueTask
of a method invocation is awaited multiple times. Awaiting the same ValueTask
can be problematic since the class behind the invoked method may recycle the underlying task. Therefore, a ValueTask
does not have the guarantee, as Task
does, that it never transitions away from the completed state.
Make sure to await
the returned ValueTask
only once. However, it is best practice to await
the method invocation rather than storing the returned ValueTask
in a local variable. If both options are not possible, transform the ValueTask
into a conventional Task
with the help of the AsTask
method (which may only be used once as well).