c#内置异步方法是否由TaskCompletionSource实现?
Does c# build-in async method implement by TaskCompletionSource?
像 streamReader.ReadAsync/downloadAsync 和许多其他异步方法,他们是否应该使用 TaskCompletionSource 来实现?
例如socket/httpclient中的SendAsync方法。当IOCP发送完成,然后IO线程池得到一个线程通知cpu它工作完成,是否应该在TaskCompletionSource.SetResult中调用c# 继续等待?
Like streamReader.ReadAsync/downloadAsync and many other async methods,Should they use TaskCompletionSource to implement?
有点。您可以将它们视为使用 TaskCompletionSource<T>
,这已经足够接近了。
从技术上讲,他们跳过 TaskCompletionSource<T>
并在 Task
上使用 non-public 方法来做同样的事情。
For example the SendAsync method in socket/httpclient.When IOCP send completely,and then IO threadpool get a thread to notify cpu that it work finished,should it call TaskCompletionSource.SetResult in c# to continue await?
有时。一些 BCL 方法在 I/O 线程池 (IOCP) 线程上完成,但大多数方法在工作线程池线程上完成。这是为了避免任何后续工作(如 await
之后的 end-user 代码)阻塞 IOCP 线程。但是上次我检查时,可以在 I/O 线程上调用一些 lower-level 回调(尤其是套接字回调)。
像 streamReader.ReadAsync/downloadAsync 和许多其他异步方法,他们是否应该使用 TaskCompletionSource 来实现?
例如socket/httpclient中的SendAsync方法。当IOCP发送完成,然后IO线程池得到一个线程通知cpu它工作完成,是否应该在TaskCompletionSource.SetResult中调用c# 继续等待?
Like streamReader.ReadAsync/downloadAsync and many other async methods,Should they use TaskCompletionSource to implement?
有点。您可以将它们视为使用 TaskCompletionSource<T>
,这已经足够接近了。
从技术上讲,他们跳过 TaskCompletionSource<T>
并在 Task
上使用 non-public 方法来做同样的事情。
For example the SendAsync method in socket/httpclient.When IOCP send completely,and then IO threadpool get a thread to notify cpu that it work finished,should it call TaskCompletionSource.SetResult in c# to continue await?
有时。一些 BCL 方法在 I/O 线程池 (IOCP) 线程上完成,但大多数方法在工作线程池线程上完成。这是为了避免任何后续工作(如 await
之后的 end-user 代码)阻塞 IOCP 线程。但是上次我检查时,可以在 I/O 线程上调用一些 lower-level 回调(尤其是套接字回调)。