tengo este código:Delegado - Excepciones No espere hasta llamar EndInvoke()
using System;
using System.Runtime.Remoting.Messaging;
class Program {
static void Main(string[] args) {
new Program().Run();
Console.ReadLine();
}
void Run() {
Action example = new Action(threaded);
IAsyncResult ia = example.BeginInvoke(new AsyncCallback(completed), null);
// Option #1:
/*
ia.AsyncWaitHandle.WaitOne();
try {
example.EndInvoke(ia);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
*/
}
void threaded() {
throw new ApplicationException("Kaboom");
}
void completed(IAsyncResult ar) {
// Option #2:
Action example = (ar as AsyncResult).AsyncDelegate as Action;
try {
example.EndInvoke(ar);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
}
En muchos artículos se destaca que cuando llamo BeginInvoke
, todos Exception
s (aquí del método threaded
) espera hasta que llamo EndInvoke
y será arrojado allí. Pero no funciona, el Exception
("Kaboom") es "no controlado" y el programa falla. ¿Me puedes ayudar?
Gracias!
Tendrá que explicar qué tiene de especial la configuración de su depurador. Como mínimo documente lo que ve Debug + Exceptions. Desactive todas las casillas de verificación allí. –