【发布时间】:2021-02-01 16:30:15
【问题描述】:
最近我对 I/O Bound 和 Cpu Bound 工作使用什么感到有点困惑,截至目前,我得出的结论(随时纠正)是:
-Task.Run() - CPU 绑定工作
-TaskCompletionSource - I/O 绑定工作
场景:
您被一种基于 i/o 的工作顺序运行的方法卡住了,您无法编辑该方法,让它异步运行的最佳选择是什么?
//method example
//Purposely avoiding using the AsyncTask Version Of DownloadString In WebClient
public void Foo()=>new WebClient.DownloadString("https://google.com");
//-------
//here is the part of the code that I will be trying to execute Foo asynchronously
await Task.Run(()=>Foo()); //wouldn't this be the only way to run this method asynchronously even though Foo isn't doing CPU Bound Work?
【问题讨论】:
-
这取决于应用程序的类型。
标签: c# .net-core async-await