当前位置:网站首页>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边栏推荐
- WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
- Win:使用 PowerShell 检查无线信号的强弱
- runc hang 导致 Kubernetes 节点 NotReady
- Using druid to connect to MySQL database reports the wrong type
- MySQL backup and recovery + experiment
- Valentine's Day flirting with girls to force a small way, one can learn
- 100 basic multiple choice questions of C language (with answers) 04
- Marubeni Baidu applet detailed configuration tutorial, approved.
- What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
- Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
猜你喜欢
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Yyds dry inventory swagger positioning problem ⽅ formula
Missile interception -- UPC winter vacation training match
Can you really learn 3DMAX modeling by self-study?
Comment mettre en place une équipe technique pour détruire l'entreprise?
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
Security level
[OpenGL learning notes 8] texture
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
如何做一个炫酷的墨水屏电子钟?
随机推荐
ICSI 311 Parser
Pgadmin 4 V6.5 release, PostgreSQL open source graphical management tool
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
Application and development trend of image recognition technology
如何做一个炫酷的墨水屏电子钟?
PowerShell: use PowerShell behind the proxy server
Summary of regularization methods
Grub 2.12 will be released this year to continue to improve boot security
100 basic multiple choice questions of C language (with answers) 04
. Net starts again happy 20th birthday
Leetcode takes out the least number of magic beans
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
Interpretation of mask RCNN paper
Why do you understand a16z? Those who prefer Web3.0 Privacy Infrastructure: nym
Learn tla+ (XII) -- functions through examples
How to make a cool ink screen electronic clock?
Numpy library introductory tutorial: basic knowledge summary
What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
Flutter 2.10 update details
Talk about the things that must be paid attention to when interviewing programmers