当前位置:网站首页>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 taskThe compiler the await Put all the code after the keyword into OnCompleted Method to convert await keyword .
边栏推荐
- 【web審計-源碼泄露】獲取源碼方法,利用工具
- SQL performance optimization skills
- [positioning in JS]
- Multimedia query
- Hot knowledge of multithreading (I): introduction to ThreadLocal and underlying principles
- MySQL winter vacation self-study 2022 11 (9)
- Talk about the SQL server version of DTM sub transaction barrier function
- Kubernetes -- cluster expansion principle
- [groovy] loop control (number injection function implements loop | times function | upto function | downto function | step function | closure can be written outside as the final parameter)
- [groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
猜你喜欢

SQL injection exercise -- sqli Labs

SPI and IIC communication protocol
![[untitled]](/img/53/f67c53d4ada382ec42f97cf68d9c71.jpg)
[untitled]

SQL performance optimization skills

El select, El option drop-down selection box

Mongodb common commands

How to learn to get the embedding matrix e # yyds dry goods inventory #

Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation

IPv6 experiment
![[groovy] string (string injection function | asBoolean | execute | minus)](/img/ea/bf1e6aa713cf54e29653e35b164560.jpg)
[groovy] string (string injection function | asBoolean | execute | minus)
随机推荐
Sqoop installation
Share the newly released web application development framework based on blazor Technology
Solve the problem that sqlyog does not have a schema Designer
C file in keil cannot be compiled
The latest blind box mall, which has been repaired very popular these days, has complete open source operation source code
Why do some programmers change careers before they are 30?
Qrcode: generate QR code from text
Simple use of devtools
How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
Nmap使用手册学习记录
There is a question about whether the parallelism can be set for Flink SQL CDC. If the parallelism is greater than 1, will there be a sequence problem?
Smart pointer shared_ PTR and weak_ Difference of PTR
Accuracy problem and solution of BigDecimal
【web源码-代码审计方法】审计技巧及审计工具
MySQL winter vacation self-study 2022 11 (9)
Quick start of UI component development of phantom engine [umg/slate]
Technology sharing swift defense programming
qrcode:将文本生成二维码
Pat class a 1160 forever (class B 1104 forever)
UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程