public delegate void ProcessHandler(Model model);//Delegation declaration
ProcessHandler msghandler = new ProcessHandler(ProcessMsg);//Instantiate a delegate
IAsyncResult iasyn = msghandler.BeginInvoke(model, new AsyncCallback(CompleteHandler), null);//Start executing the processing process
//The function called when the main processing process ends
static void CompleteHandler(IAsyncResult asyn)
{
AsyncResult ar = (AsyncResult)asyn ;
ProcessHandler del = (ProcessHandler)ar.AsyncDelegate;
del.EndInvoke(asyn);
}
static void ProcessMsg(Model model){
//Main processing process
}
The above is the detailed content of C# uses delegation for asynchronous processing example code. For more information, please follow other related articles on the PHP Chinese website!