其他分享
首页 > 其他分享> > WebApi踩坑记

WebApi踩坑记

作者:互联网

1

Api使用Furion时,使用了List.ForEach( acction())  action中Throw Bah.Oh(...) 

 

 1 [HttpGet]
 2 public async Task<int> ListForeach()
 3         { 
 4             string[] list = { "1", "2", "3" };
 5             list.ToList().ForEach(async x => {
 6                 if (x == "3")
 7                     await OtherFun(x);
 8                 Console.WriteLine(x); });    
 9          }
10 private async Task OtherFun(string id)
11         {
12                 throw Furion.FriendlyException.Oops.Bah("error");
13         }

2 void 返回值API

 [HttpGet]
        public void ListForeach()
        {
            DoThat that = new DoThat();
            that.Do();
        }

    interface DoSomethings
        {
            void Do();
        }

class DoThat : DoSomethings
        {
            public async void Do()
            {
                await Task.Run(() => throw Furion.FriendlyException.Oops.Oh("123"));
            }
        }

最开始以为是返回值的类型问题,后来发现是属同一个问题?什么问题,后面再写

 

标签:WebApi,坑记,Task,DoThat,Do,void,async,public
来源: https://www.cnblogs.com/stweily/p/16481380.html