ho questo codice:Delegato - Eccezioni non aspettare fino a quando chiama 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);
}
}
}
In molti articoli stand che quando chiamo BeginInvoke
, tutti Exception
s (qui dal metodo threaded
) attendere che io chiamo EndInvoke
e verrà lanciato lì. Ma non funziona, lo Exception
("Kaboom") è "non gestito" e il programma si blocca. Potete aiutarmi?
Grazie!
Avrete bisogno di spiegare cosa c'è di speciale nella configurazione del debugger. Per lo meno documenta ciò che vedi Debug + Eccezioni. Spegni tutte le caselle di controllo lì. –