internal void InvokeAsync(object[] parameters, Client.Action <object> returnTResultAsync) { _callback.BeginInvoke(parameters, (ar) => { Client.Func <object[], object> method = (Client.Func <object[], object>)ar.AsyncState; //委托执行的异常会在EndInvoke时抛出来 try { var result = method.EndInvoke(ar); Log.Debug($"执行 EndInvoke 后 IAsyncResult.Completed={ar.IsCompleted}"); // 方法执行完成后执行指定的异步方法 if (!ar.IsCompleted) { throw new OverflowException($"IAsyncResult Is Not Completed"); } returnTResultAsync?.BeginInvoke(result, null, null); } catch (OverflowException oe) { Log.Error($"{nameof(InvocationHandler)} 执行 EndInvoke 出错", oe); throw oe; } }, _callback); }
public InvocationHandler(Type[] parameterTypes, Type returnType, Client.Func <object[], object> callback) { ParameterTypes = parameterTypes; ReturnType = returnType; _callback = callback; }