이 코드가 어떻게 작동하는지 사용자가 알 수 있습니까? 코드에 삽입 된 주석을 확인하십시오 ...대리자를 통해 대체 가능한 메서드를 실행할 때 Invoke() 및 BeginInvoke()가 다르게 동작
여기에 정말 분명한 것을 놓치고 있습니까?
using System;
namespace ConsoleApplication3
{
public class Program
{
static void Main(string[] args)
{
var c = new MyChild();
c.X();
Console.ReadLine();
}
}
public class MyParent
{
public virtual void X()
{
Console.WriteLine("Executing MyParent");
}
}
delegate void MyDelegate();
public class MyChild : MyParent
{
public override void X()
{
Console.WriteLine("Executing MyChild");
MyDelegate md = base.X;
// The following two calls look like they should behave the same,
// but they behave differently!
// Why does Invoke() call the base class as expected here...
md.Invoke();
// ... and yet BeginInvoke() performs a recursive call within
// this child class and not call the base class?
md.BeginInvoke(CallBack, null);
}
public void CallBack(IAsyncResult iAsyncResult)
{
return;
}
}
}
이 시도하거나 문제가 발생했습니다 알고 있었다, 그러나 나는이에서 오는 문제를 많이 볼 수 없다. 아마도 누군가가 설명 할 수 있습니다. – leppie