// 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);
}