C # brief asynchronous processing instance

Source: Internet
Author: User
// Declare a delegate
Public Delegate string addhandler (int A, string B); // you need to specify the number of parameters here. In this example, there are only two parameters.

Void calls asynchronous ()
{

Addhandler handler = new addhandler (ADD );

// Use begininvoke to start asynchronous operations. Here, 1, "string", the two parameters are corresponding (int A, string B)
Iasyncresult result = handler. begininvoke (1, "string", new asynccallback (addcomplete), "What object do you want to write ");

}

static int add (int A, string B)
{< br> // The processing function
thread. sleep (3000); // simulate time-consuming Operations
return B +. tostring ();
}

static void addcomplete (iasyncresult result)
{< br> addhandler handler = (addhandler) (asyncresult) result ). asyncdelegate;
// After debugging, you will understand
MessageBox. show (handler. endinvoke (result);
MessageBox. show (result. asyncstate);
}

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.