[] Asynchronous programming continues

Source: Internet
Author: User

I 've been watching asynchronous programming for two days, and it's hard to understand. I don't know what I understand.

Public Delegate int taskwhiledelegate (INT data, int MS); // defines the delegate

// Delegate Method

Static int taskwhile (INT data, int MS)
{
Console. writeline ("taskwhilestart ");
Thread. Sleep (MS );
Console. writeline ("taskwhilecomplete ");
Return ++ data;
}

Static void main (string [] ARGs)
{
Taskwhiledelegate TD = new taskwhiledelegate (taskwhile );
Iasyncresult IAS = TD. begininvoke (1, 3000, null, null );
While (! IAS. iscompleted)
{
Console. writeline (".");
Thread. Sleep (50 );
}
Int result = TD. endinvoke (IAS );
Console. writeline ("Result: {0}", result );
Console. readkey ();

}

Do not know whether to understand or not. According to the output, the main function is the main process. First, an asynchronous delegate is created. To execute the taskwhile method.

Determine whether the enabled process is finished and the output is not completed. Then the main thread is sleeping for 50 ms, the asynchronous thread executes the output taskwhilestart, and sleep for 3000 Ms.

[] Asynchronous programming continues

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.