.net core微服务 async task job示例

 

Execute函数

 public async Task Execute(IJobExecutionContext context)
 {
     Stopwatch _time = new Stopwatch();
     _time.Start();
     string strRe = "开始时间:" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
     string errmsg = string.Empty;
     string orderNo = string.Empty;

     try
     {
         var res = await DealSomething(orderNo, errmsg);
         var terst = res.orderNo;
         var testErrmsg = res.errMsgElk;
     }
     catch (Exception ex)
     {
         errmsg += ex.Message;
     }

     _time.Stop();
     var excuteTime = _time.Elapsed.TotalMilliseconds;
     

 }

  dealSomething方法

public async Task<(string orderNo,string errMsgElk)> DealSomething(string orderNo, string errMsgElk)
{
   var order = await _orderService.GetAirOrder(order);
  return ("test", "");
}

  sercive里异步代码

public async Task<AirOrder> GetAirOrder(T_YW_Orders order)
{
    var ticketInfos = await _orderTicketService.FindAsync(s => s.OrderNo == order.OrderNo);
   return new AirOrder();
}

  

 

posted on 2024-11-19 10:54  御行所  阅读(1)  评论(0编辑  收藏  举报

导航