当前位置:网站首页>From task Run get return value - getting return value from task Run
From task Run get return value - getting return value from task Run
2022-07-05 02:19:00 【French red wine sweet】
problem :
I have the following code: I have the following code :
public static async Task<string> Start(IProgress<ProcessTaskAsyncExProgress> progress){ const int total = 10; for (var i = 0; i <= total; i++) { await Task.Run(() => RunLongTask(i.ToString(CultureInfo.InvariantCulture))); if (progress != null) { var args = new ProcessTaskAsyncExProgress { ProgressPercentage = (int)(i / (double)total * 100.0), Text = "processing " + i }; progress.Report(args); } } return "Done";}private static string RunLongTask(string taskName){ Task.Delay(300); return taskName + "Completed!";}
How do I get back the string value of RunLongTask
from this line: await Task.Run(() => RunLongTask(i.ToString(CultureInfo.InvariantCulture)));
How to start from this line RunLongTask
The string value of : await Task.Run(() => RunLongTask(i.ToString(CultureInfo.InvariantCulture)));
??
I've tried: I tried :
var val = await Task.Run(() => RunLongTask(i.ToString(CultureInfo.InvariantCulture))).Result;
But I get an error saying "string is not awaitable". But I received an error message , say “ String cannot wait ”.
Solution :
Reference resources : https://stackoom.com/en/question/1DjqW边栏推荐
- Unified blog writing environment
- Tla+ through examples (XI) -- propositional logic and examples
- Official announcement! The third cloud native programming challenge is officially launched!
- One click generation and conversion of markdown directory to word format
- Huawei machine test question: longest continuous subsequence
- Stored procedure and stored function in Oracle
- Grpc message sending of vertx
- Security level
- 【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
- Restful fast request 2022.2.1 release, support curl import
猜你喜欢
Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
Application and Optimization Practice of redis in vivo push platform
One plus six brushes into Kali nethunter
Action News
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
"2022" is a must know web security interview question for job hopping
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
如何搭建一支搞垮公司的技術團隊?
[technology development-26]: data security of new information and communication networks
随机推荐
Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
Application and Optimization Practice of redis in vivo push platform
Interpretation of mask RCNN paper
Prometheus monitors the correct posture of redis cluster
Process scheduling and termination
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
Android advanced interview question record in 2022
Variables in postman
Runc hang causes the kubernetes node notready
Unified blog writing environment
Numpy library introductory tutorial: basic knowledge summary
如何做一个炫酷的墨水屏电子钟?
100 basic multiple choice questions of C language (with answers) 04
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
Flutter 2.10 update details
Can you really learn 3DMAX modeling by self-study?
[technology development-26]: data security of new information and communication networks
Chinese natural language processing, medical, legal and other public data sets, sorting and sharing
Pytorch register_ Hook (operate on gradient grad)