問(wèn)題在代碼里:
using System;
using System.Threading;
using System;
using System.Threading;
namespace ThreadPoolApplication
{
class Program
{
static int count = 5;
static void Main(string[] args)
{
Test t=new Test ();
ReStringMths r=new ReStringMths (t.Exec);
r.BeginInvoke(new System.AsyncCallback((IResult)=>{r.EndInvoke(IResult);Console.WriteLine("類名為{0}的異步方法{1}執(zhí)行完畢!",IResult.AsyncState.ToString(),IResult.AsyncState.GetType().GetMethods()[0].Name);}),t);
//問(wèn)題1:請(qǐng)問(wèn)r.EndInvoke(IResult);這個(gè)IResult傳進(jìn)去干嘛用的?用于什么情況下?
//問(wèn)題2:有什么辦法可以獲取t.Exec的返回值?
//問(wèn)題3:不寫r.EndInvoke(IResult);同樣可以得到正確結(jié)果...但是為什么要有r.EndInvoke方法呢?
System.Console.ReadKey();
}
}
delegate string ReStringMths();
class Test
{
public string Exec()
{
System.Console.WriteLine("Start..."); Thread.Sleep(5000); System.Console.WriteLine("End..."); return "hello";
}
}
}
新手..問(wèn)題多多..麻煩各位了!
C# 關(guān)于線程異步調(diào)用的基礎(chǔ)問(wèn)題...
www說(shuō)
2018-12-06 14:14:26