public static class ExtensionMethods public static TaskAwaiter GetAwaiterthis AsyncOperation asyncOp var tcs = new TaskCompletionSourceobject; asyncOpcompleted += obj =
This extension method adds the GetAwaiter method to the AsyncOperation class. This allows you to use the await keyword with instances of AsyncOperation.
The GetAwaiter method creates a TaskCompletionSource object, which represents an asynchronous operation that can be awaited. It then subscribes to the completed event of the AsyncOperation object, and when the event is triggered, it sets the result of the TaskCompletionSource to null.
Finally, it returns the awaiter of the Task object created from the TaskCompletionSource.Task. The awaiter is responsible for handling the asynchronous waiting and continuation logic
原文地址: https://www.cveoy.top/t/topic/iRDg 著作权归作者所有。请勿转载和采集!