Home  >  Article  >  Backend Development  >  C# uses delegation for asynchronous processing example code

C# uses delegation for asynchronous processing example code

零下一度
零下一度Original
2017-06-26 15:35:011531browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn