, . , -.
, 'onA' , onA() .
"Foo" "OnFoo", . , , - : -
class Foo
{
public delegate void ADelegate();
public event ADelegate A;
private void OnA()
{
if(A != null)
A();
}
public void Func()
{
OnA();
}
}
, BeginInvoke() EndInvoke(), : -
class Foo
{
public delegate void ADelegate();
public event ADelegate A;
private void OnA()
{
if (A == null) return;
foreach(ADelegate del in A.GetInvocationList())
del.BeginInvoke(SubscriberCallback, del);
}
private void SubscriberCallback(IAsyncResult result)
{
var del = (ADelegate) result.AsyncState;
del.EndInvoke(result);
}
public void Func()
{
OnA();
}
}
, (-) , , .
Please note that the "callback" is the method that you specify in the asynchronous BeginInvoke (since it "appealed" after the async-work) and does not return to Func (), because it is executed in a separate thread.
source
share