using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using System.Threading ;</p><p>namespace 多線程<br />{<br /> class Program<br /> {<br /> public delegate int TakesAwhileDel ( int data , int ms ) ;<br /> static void Main(string[] args)<br /> {<br /> //非同步委託<br /> TakesAwhileDel dl = TakesAwhile ;<br /> IAsyncResult re = dl.BeginInvoke( 1 , 3000 , null , null ) ;</p><p> while( !re.IsCompleted )<br /> {<br /> Console.WriteLine( "等" ) ;<br /> Thread.Sleep( 50 ) ;<br /> }</p><p> int result = dl.EndInvoke( re ) ;<br /> Console.WriteLine( "最後結果{0}" , result.ToString() ) ;<br /> Console.ReadLine() ;<br /> }</p><p> static int TakesAwhile( int data , int ms )<br /> {<br /> Console.WriteLine( "開始調用" ) ;<br /> Thread.Sleep( ms ) ;<br /> Console.WriteLine( "完成調用" ) ;<br /> return ++ data ;<br /> }<br /> }<br />}<br />