public delegate void ProcessHandler(Model model);//委託申明
ProcessHandler msghandler = new ProcessHandler(ProcessMsg);//實例化一個委託
IAsyncResult iasyn = msghandler.Begin,Invoke(model AsyncCallback(CompleteHandler), null);//開始執行處理過程
//主處理過程結束呼叫的函數
static void CompleteHandler(IAsyncResult asyn)
{
AsyncResult ar = (AsyncResult)asyn ;
ProcessHandler del = (ProcessHandler)ar.AsyncDelegate;
del.EndInvoke(asyn);
}
static void ProcessMsg(Model model){
//主處理過程
}
以上是C# 利用委託進行非同步處理實例程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!