Basic usages and examples of C # Task.fromresult

Source: Internet
Author: User

Basic usages and examples of C # Task.fromresult

This method is useful if you perform an asynchronous operation that returns a Task object, and the result of that task O Bject is already computed

There is common use cases I ' ve found:

    1. When you ' re implementing a interface that allows asynchronous callers, but your implementation is synchronous.
    2. When your ' re stubbing/mocking asynchronous code for testing

The above is generally used for unit testing;

Then there are also useful when we read the cache; Microsoft Official blog instance;

Https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-create-pre-computed-tasks

The thought above:

This method is useful if you perform an asynchronous operation that returns a Task object, and the result of that task O Bject is already computed.

has been calculated, or has been cached, the basic desired value;

Basic usages and examples of C # Task.fromresult

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.