. MSDN , , :)
, . MSDN. http://msdn.microsoft.com/en-us/magazine/cc164139.aspx
, ( , ) BeginInvoke EndInvoke .NET CLR. , , .
CLR Via #.
. , .
.Invoke Winforms. .
WPF Control.Invoke. WPF Control.
. .
, .
, MSDN, .
( msdn http://msdn.microsoft.com/en-us/library/ms173171(v=vs.80).aspx)
public delegate int PerformCalculation(int x, int y);
, ( "d" ). . PerformCalculation, .
, , .
, , :
using System;
delegate void SampleDelegate(string message);
class TestDelegate
{
private void CallMeUsingDelegate(string m_param)
{
Console.WriteLine("Called me using parameter - " + m_param);
}
public static void Main(string[] args)
{
SampleDelegate sd = new SampleDelegate(CallMeUsingDelegate);
sd.Invoke("FromMain");
}
}
CallMeUsingDelegate . # , .
,
System; // - : void SampleDelegate ( );
class TestDelegate
{
public static void Main(string[] args)
{
SampleDelegate sd = delegate(param) {
Console.WriteLine("Called me using parameter - " + param);
};
sd.Invoke("FromMain");
}
}
, . .
IL . 2 .
BeginInvoke EndInvoke, . threadpool, CLR.
, , ,
IAsyncResult ar = sd.BeginInvoke(CallMeUsingDelegate, callMeOnCompletion, sd);
Delegate - , . , , Thread BeginInvoke, , Delegate, ThreadPool CLR. , IAsyncResult. , ( , sd 3).
CallMeUsingDelegate (ThreadPool). , ThreadPool , 2 .
, , EndInvoke, ???
, , EndInvoke, CLR ThreadPool , . EndInvoke .
, ( ), .