当前位置:网站首页>C # use awaiter
C # use awaiter
2022-07-05 03:39:00 【Dotnet cross platform】
Can be provided to any GetAwaiter Method and return awaiter Object using async keyword .awaiter use OnCompleted Method realization INotifyCompletion Interface . This method is called when the task is completed . The following code snippet is not used in a task await, But using tasks GetAwaiter Method .Task Class GetAwaiter Return to one TaskAwaiter. Use OnCompleted Method , Assign a local function to be called when the task is complete :
private static void CallerWithAwaiter()
{
TraceThreadAndTask($"starting {nameof(CallerWithAwaiter)}");
TaskAwaiter<string> awaiter = GreetingAsync("Matthias").GetAwaiter();
awaiter.OnCompleted(OnCompleteAwaiter);
void OnCompleteAwaiter()
{
Console.WriteLine(awaiter.GetResult());
TraceThreadAndTask($"ended {nameof(CallerWithAwaiter)}");
}
}
When running the application , The result is similar to that you use wait Keyword case :
starting CallerWithAwaiter in thread 2 and no task
running GreetingAsync in thread 3 and task 1
running Greeting in thread 3 and task 1
Hello,Matthias
ended CallerWithAwaiter in thread 3 and no task
The compiler the await Put all the code after the keyword into OnCompleted Method to convert await keyword .
边栏推荐
- De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
- El tree whether leaf node or not, the drop-down button is permanent
- Sqoop installation
- [untitled]
- Pat class a 1160 forever (class B 1104 forever)
- qrcode:将文本生成二维码
- Clean up PHP session files
- KVM virtualization
- Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
- Clickhouse同步mysql(基于物化引擎)
猜你喜欢
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
Flume configuration 4 - customize mysqlsource
【web審計-源碼泄露】獲取源碼方法,利用工具
【web源码-代码审计方法】审计技巧及审计工具
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
[wp][入门]刷弱类型题目
Port, domain name, protocol.
【软件逆向-分析工具】反汇编和反编译工具
Accuracy problem and solution of BigDecimal
error Couldn‘t find a package.json file in “你的路径“
随机推荐
VM in-depth learning (XXV) -class file overview
Qrcode: generate QR code from text
[move pictures up, down, left and right through the keyboard in JS]
51 independent key basic experiment
LeetCode146. LRU cache
qrcode:将文本生成二维码
Subversive cognition: what does SRE do?
postman和postman interceptor的安装
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
【软件逆向-基础知识】分析方法、汇编指令体系结构
Une question est de savoir si Flink SQL CDC peut définir le parallélisme. Si le parallélisme est supérieur à 1, il y aura un problème d'ordre?
Necessary fonts for designers
Why do some programmers change careers before they are 30?
MySQL winter vacation self-study 2022 11 (10)
speed or tempo in classical music
【web審計-源碼泄露】獲取源碼方法,利用工具
NPM introduction link symbolic link
Azkaban actual combat
An elegant program for Euclid‘s algorithm
Dart series: collection of best practices