您好,登錄后才能下訂單哦!
把代碼過(guò)程經(jīng)常用的內(nèi)容做個(gè)珍藏,如下代碼是關(guān)于C#中異步回調(diào)函數(shù)演示的代碼,應(yīng)該是對(duì)大伙有些用途。
static void Main(string[] args)
{
Func<string,string> showMessage = ShowMessage;
IAsyncResult result = showMessage.BeginInvoke("測(cè)試異步委托", new AsyncCallback(Completed), null);
while(!result.IsCompleted)
{
Console.WriteLine("主線程可以進(jìn)行其它的操作!");
}
Console.ReadLine();
}
static string ShowMessage(string x)
{
string current = string.Format("當(dāng)前線程id為{0}",Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(3000);
return string.Format("{0},輸入為{1}", current, x);
}
static void Completed(IAsyncResult result)
{
Console.WriteLine("異步完成!");
AsyncResult _result = (AsyncResult) result;
Func<string, string> showMessage = (Func<string, string>) _result.AsyncDelegate;
Console.WriteLine(showMessage.EndInvoke(_result));
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。