मैं इस कोड है:प्रतिनिधि - अपवाद 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);
}
}
}
कई लेख में खड़ा है कि जब मैं BeginInvoke
, सभी Exception
रों (विधि threaded
से यहाँ) कहते हैं जब तक प्रतीक्षा करें मैं फोन EndInvoke
और वहां फेंक दिया जाएगा। लेकिन यह काम नहीं करता है, Exception
("Kaboom") "unhandled" है और प्रोग्राम क्रैश हो जाता है। क्या आप मेरी मदद कर सकते हैं?
धन्यवाद!
आपको यह समझाने की आवश्यकता होगी कि आपके डीबगर सेटअप के बारे में क्या विशेष है। कम से कम दस्तावेज़ पर आप डीबग + अपवादों को देखते हैं। वहां कोई भी चेक-बॉक्स बंद करें। –