¿Alguien puede decirme por qué este código se comporta de la manera en que lo hace? Ver comentarios incrustados en el código ...Invoke() y BeginInvoke() comportándose de manera diferente al ejecutar un método sobrescribible a través de un delegado
¿Me falta algo realmente obvio aquí?
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;
}
}
}
no he probado esto, o fue consciente de que había un problema, pero puedo ver una gran cantidad de problemas que vienen de esto. Tal vez alguien pueda explicar :) – leppie