public static void CallAsyncFunc(BinaryReader br, BinaryWriter bw, IPAddress address) { if (!CallAsFuncAll(br, bw, out var result, false)) { return; } try { var taskId = new Guid(br.ReadBytes(16)); var port = br.ReadInt32(); var typeInfo = result.GetType().GetTypeInfo(); var asyncCallBack = new TcpAsyncCallBack(taskId, address, port); var callBack = new Action <bool, object>(asyncCallBack.SendAsyncMessage); if (!typeInfo.IsGenericType) { AsyncRunner.TaskExecute((Task)result, callBack); return; } var args = new[] { result, callBack }; var method = InformationOnTheTypes.FindMethod(typeof(AsyncRunner), true, "Execute", args); if (method == null) { SetError("Неверный результат", bw); return; } method.ExecuteMethod(null, args); } catch (Exception e) { SetError(AutoWrap.GetExceptionString("Ошибка вызова делегата", "", e), bw); return; } bw.Write(true); WorkWithVariant.WriteObject(null, bw); }