Я думал, что этот подход будет безопасным, поскольку он не позволит распространять исключения. Мой коллега предположил, что исключения должны соблюдаться в главном потоке и, следовательно, должны передаваться в основной поток. Это ответ? Вы видите, как через это может протекать исключение?
private static void InvokeProcessHandlers<T>(List<T> processHandlers, Action<T> action)
{
// Loop through process handlers asynchronously, giving them each their own chance to do their thing.
Task.Factory.StartNew(() =>
{
foreach (T handler in processHandlers)
{
try
{
action.Invoke(handler);
}
catch (Exception ex)
{
try
{
EventLog.WriteEntry(ResourceCommon.LogSource,
String.Format(CultureInfo.CurrentCulture, "An error occurred in a pre- or post-process interception handler: {0}", ex.ToString()),
EventLogEntryType.Error);
}
catch (Exception)
{
// Eat it. Nothing else we can do. Something is seriously broken.
}
continue; // Don't let one handler failure stop the rest from processing.
}
}
});
}
Кстати, трассировка стека действительно показывает, что из этого метода вытекает исключение.
Исключением является AccessViolation, и я считаю, что это связано с кодом, вызывающим этот метод:
InvokeProcessHandlers<IInterceptionPostProcessHandler>(InterceptionPostProcessHandlers, handler => handler.Process(methodCallMessage, methodReturnMessage));
Получатель для InterceptionPostProcessHandlers содержит это:
_interceptionPreprocessHandlers = ReflectionUtility.GetObjectsForAnInterface<IInterceptionPreprocessHandler>(Assembly.GetExecutingAssembly());