Async and await in C #

Source: Internet
Author: User

public class MyClass
{
Public MyClass ()
{
Displayvalue (); There's no blocking.
System.Diagnostics.Debug.WriteLine ("MyClass () End.");
}
Public task<double> Getvalueasync (double num1, double num2)
{
Return Task.run (() =
{
for (int i = 0; i < 1000000; i++)
{
NUM1 = num1/num2;
}
return NUM1;
});
}
Public async void Displayvalue ()
{
Double result = await Getvalueasync (1234.5, 1.01);//This will open a new thread to process the Getvalueasync task, then return the method immediately
All code after this is encapsulated as a delegate, which is called when the Getvalueasync task completes.
System.Diagnostics.Debug.WriteLine ("Value is:" + result);
}
}

Async and await in C #

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.