C# Task.ContinueWith 返回对象

使用Task.ContinueWith 可以在Task完成时而继续执行的逻辑

当在ContinueWith中需要返回一个对象时,应该如何使用

 下方代码可以表示,在设置缓存完成后,重新读取缓存,并返回

 var item = await SetCacheItemAsync("key",  cacheItems)
                .ContinueWith<>(async _ => await cacheItem.GetAsync(key));

 

  

posted @ 2021-11-17 17:09  C_supreme  阅读(357)  评论(0编辑  收藏  举报