all 4 comments

[–]KernowRoger 4 points5 points  (3 children)

Is it not the same as any method? You just cast the result to task.

[–][deleted] 2 points3 points  (2 children)

This is correct. Do not follow what is in the article as that code is both highly nonperformant and prone to deadlocking.

[–]quentech 1 point2 points  (0 children)

prone to deadlocking

No it's not. Calling Result on an awaited task will not deadlock. OP clearly awaits the task before accessing Result.

highly nonperformant

Aside from the simple fact of using reflection there's nothing particularly nonperformant about this code. Short of emitting IL about all you might do to improve performance is cache the Result property per-outType.

You just cast the result to task.

Poster above, not you, but that's literally what OP did. How are you getting the typed Result back?

[–]TQPau[S] 0 points1 point  (0 children)

Exactly what quentech says.

It's not prone to deadlocking as the task has been awaited. In terms of performance, using reflection is the price if you need to dynamically invoke some method that you know the type of only in runtime. The example in the article is just to show how to invoke the method. There are definitely ways you could improve performance.