• GetAwaiter和GetResult


    这两个用法其实我也还是没有怎么搞懂,先记录下吧

     HttpContent content = new StringContent(JsonConvert.SerializeObject(o), Encoding.UTF8, "application/json");
     var myhttpclient = _myhttpclientfactory.CreateClient();
     var message = Task.Run(() =>
     {
         return myhttpclient.PostAsync(url, content);
     });
     message.Wait();
     _Database.Add(new jsonlog
     {
             Time = Now.DateTime,
             Fk = Id,
             Json = JsonConvert.SerializeObject(o),
             Pk = System.Guid.NewGuid(),         
             Msg = $ "{OrderNum}"
     });
     _Database.SaveChanges();
     if(message.Result.IsSuccessStatusCode)
     {
         var rr = message.Result.Content.ReadAsStringAsync().GetAwaiter().GetResult();
         _Database.OmsEcjsonlog.Add(new OmsEcjsonlog
         {
                 CreateDateTime = Now.DateTime,
                 Fk = Id,
                 Json = rr,
                 Pk = System.Guid.NewGuid(),            
                 Msg = $ "{OrderNum}"
         });
         _Database.SaveChanges();
         var j = JObject.Parse(rr);   
         string flag = j["response"]["success"].ToString();
         string msg = j["response"]["msg"].ToString();
         if(flag.ToLower() == "true" || msg == "ok")
         {
             using(var tran = _OMSECDatabase.Database.BeginTransaction())
             {
                 try
                 {
                     tran.Commit();
                     i = 1;
                 }
                 catch(Exception ex)
                 {
                     if(tran != null) tran.Rollback();
                     throw new Exception($ "SO Cancel Tran Failed,{ex.Message}");
                 }
             }
         }
         else
         {}
     }

    找了两个相关链接 A B 微软DOC

  • 相关阅读:
    把工作当恋人-第一天
    python入门脚本练习之列表list
    python之sqlite安装
    pycharm 中提示:this license **** has been cancelled
    使用python计算圆的面积
    python中随机生成数
    python中的paramiko模块
    linux下的python如何使用tab键补全
    centos6.5安装python
    mysql常用命令
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/13468871.html
Copyright © 2020-2023  润新知