c# Task.FromResult 的基本用法和實例
This method is useful when you perform an asynchronous operation that returns a Task object, and the result of that Task object is already computed
There are two common use cases I've found:
- When you're implementing an interface that allows asynchronous callers, but your implementation is synchronous.
- When you're stubbing/mocking asynchronous code for testing
上面總體來說是用於單元測試;
然后還有在我們讀取緩存的時候有用; 微軟官方博客實例;
https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-create-pre-computed-tasks
上面的思想:
This method is useful when you perform an asynchronous operation that returns a Task object, and the result of that Task object is already computed.
已經計算出來了,或者已經緩存好了,基本想要的值;
這里添加一個基本的鏈接功能:
那就是我們的異步方法中的 進度報告的問題;https://social.technet.microsoft.com/wiki/contents/articles/19020.progress-of-a-task-in-c.aspx
效果是非常好的呀;
