Код: Выделить всё
using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExceptionInterceptor
{
class Program
{
[STAThread]
static void Main(string[] args)
{
var exceptionInterceptor = new ExceptionInterceptor();
Task.Run(() =>
{
//int a = 1;
//int b = a / 0;
throw new TargetInvocationException(new Exception("Test "));
});
Console.WriteLine();
Console.ReadKey();
}
}
public class ExceptionInterceptor
{
public ExceptionInterceptor()
{
Exception();
}
public void Exception()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
};
Application.ThreadException += (sender, args) =>
{
};
TaskScheduler.UnobservedTaskException += (sender, args) =>
{
};
AppDomain.CurrentDomain.FirstChanceException += (sender, e) =>
{
};
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
return null;
};
}
}
}
Моя задача - создать один глобальный обработчик ошибок независимо от потока. Можно ли это сделать?
Подробнее здесь: https://stackoverflow.com/questions/795 ... press-them