当前位置:网站首页>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边栏推荐
- Redis' hyperloglog as a powerful tool for active user statistics
- A tab Sina navigation bar
- Chinese natural language processing, medical, legal and other public data sets, sorting and sharing
- Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
- Huawei machine test question: longest continuous subsequence
- Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
- [uc/os-iii] chapter 1.2.3.4 understanding RTOS
- Three properties that a good homomorphic encryption should satisfy
- Runc hang causes the kubernetes node notready
- Interpretation of mask RCNN paper
猜你喜欢
Traditional chips and AI chips
Restful Fast Request 2022.2.1发布,支持cURL导入
[uc/os-iii] chapter 1.2.3.4 understanding RTOS
He was laid off.. 39 year old Ali P9, saved 150million
The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
Yolov5 model training and detection
. Net starts again happy 20th birthday
如何搭建一支搞垮公司的技術團隊?
PowerShell: use PowerShell behind the proxy server
Win:使用 PowerShell 检查无线信号的强弱
随机推荐
Educational Codeforces Round 122 (Rated for Div. 2) ABC
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Win:使用组策略启用和禁用 USB 驱动器
Process scheduling and termination
How to find hot projects in 2022? Dena community project progress follow-up, there is always a dish for you (1)
Timescaledb 2.5.2 release, time series database based on PostgreSQL
Advanced conditional statements of common SQL operations
Learn tla+ (XII) -- functions through examples
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
Visual studio 2019 set transparent background (fool teaching)
Exploration of short text analysis in the field of medical and health (II)
One plus six brushes into Kali nethunter
Codeforces Round #770 (Div. 2) ABC
[illumination du destin - 38]: Ghost Valley - chapitre 5 Flying clamp - one of the Warnings: There is a kind of killing called "hold Kill"
Pgadmin 4 V6.5 release, PostgreSQL open source graphical management tool
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
Redis distributed lock, lock code logic
PowerShell: use PowerShell behind the proxy server
How to build a technical team that will bring down the company?
Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide