What is the use for Task.FromResult in C#

In C# and TPL (Task Parallel Library), the Task class represents an ongoing work that produces a value of type T.

I’d like to know what is the need for the Task.FromResult method ?

That is: In a scenario where you already have the produced value at hand, what is the need to wrap it back into a Task?

The only thing that comes to mind is that it’s used as some adapter for other methods accepting a Task instance.

6 Answers
6

Leave a Comment