J'ai entendu dire par une personne très perspicace qu'une exception étant lancée (et non interceptée) dans un thread est propagée au thread parent. Est-ce vrai? J'ai essayé quelque chose comme ça mais je n'ai pas pu attraper l'exception dans le thread de création.Exceptions dans une application multithread.
static void Main(string[] args)
{
ParameterizedThreadStart pts =
new ParameterizedThreadStart(ThreadMethod);
try
{
Thread t = new Thread(pts);
t.Start(new object());
Console.ReadLine();
}
catch (Exception ex) //the exception is not caught
{
Debugger.Break();
}
}
static void ThreadMethod(object @object)
{
Thread.Sleep(2000);
throw new IndexOutOfRangeException();
Thread.CurrentThread.Abort();
}
Je suis sûr qu'il ne le jeter dans le fil il arrive, si vous voulez voir si une exception est pris utilisation http://msdn.microsoft.com/en-us/library/system. componentmodel.backgroundworker.runworkercompleted.aspx backgroundworker à la place –