static void Main(string[] args) { Request request = new Request() { Id = 1, Name = "Rock", Address = "携程" }; Response response = new Response(); TempOrder tmpOrder = new TempOrder(); List<LogicException> exceptionList = new List<LogicException>(); try { DoWorking canBooking = new DoWorking(tmpOrder.CanBooking); IAsyncResult canBookingResult = canBooking.BeginInvoke(request,response,exceptionList,null,null); DoWorking saveOrder = new DoWorking(SaveOrder); IAsyncResult saveOrderResult = saveOrder.BeginInvoke(request, response, exceptionList, null, null); DoWorking paymentInfo = new DoWorking(tmpOrder.GetPaymentInfo); IAsyncResult paymentInfoResult = paymentInfo.BeginInvoke(request, response, exceptionList, null, null); bool result = true; int count = 0; while (result && count < 100000) { count++; if (canBookingResult.IsCompleted && saveOrderResult.IsCompleted && paymentInfoResult.IsCompleted) { Console.WriteLine("全部完成....."); result = false; } else { Console.WriteLine("还没有全部完成...."); result = true; } } if(exceptionList !=null && exceptionList.Count>0) { throw exceptionList.FirstOrDefault(); } //canBookingResult. Console.WriteLine(response.ToString()); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine("处理异常了,," + ex.Message); Console.ReadKey(); //throw; } }
public void CanBooking(Request request, Response response,List<LogicException> exceptionList) { Console.WriteLine("CanBooking Woking...."); response.Id = request.Id; Thread.Sleep(200); }
public void GetPaymentInfo(Request request, Response response, List<LogicException> exceptionList) { Console.WriteLine("GetPaymentInfo Woking...."); response.Address = request.Address; Thread.Sleep(200); }
public static void SaveOrder(Request request, Response response, List<LogicException> exceptionList) { try { response.Name = request.Name; Thread.Sleep(500); Console.WriteLine("SaveOrder Woking...."); request.HaveException(); } catch (Exception ex) { exceptionList.Add(new LogicException(ex.Message)); } }