c# - How to handle exceptions from async method with using Enterprise Library? -
exceptioncallhandler
default exception call handler in enterprise library, doesn't work async methods.
how should rewrite handler work async methods?
it code, doesn't work.
public imethodreturn invoke(imethodinvocation input, getnexthandlerdelegate getnext) { if (input == null) throw new argumentnullexception("input"); if (getnext == null) throw new argumentnullexception("getnext"); imethodreturn methodreturn = getnext()(input, getnext); methodinfo methodinfo = input.methodbase methodinfo; bool istask = methodinfo != null && typeof(task).isassignablefrom(methodinfo.returntype); task continuetask = null; if (istask) { task task = methodreturn.returnvalue task; if (task != null) { continuetask = task.continuewith((t) => { if (t.exception != null) { methodreturn.exception = t.exception.flatten().innerexception; } }, taskscheduler.fromcurrentsynchronizationcontext()); } } if (continuetask != null) { continuetask.wait(); } handlemethodreturnexception(methodreturn, input); return methodreturn; }
Comments
Post a Comment