当前位置:网站首页>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边栏推荐
- Grub 2.12 will be released this year to continue to improve boot security
- Limited query of common SQL operations
- PowerShell:在代理服务器后面使用 PowerShell
- Codeforces Global Round 19 ABC
- Go RPC call
- Application and Optimization Practice of redis in vivo push platform
- Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
- . Net starts again happy 20th birthday
- 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!
- One plus six brushes into Kali nethunter
猜你喜欢

JVM - when multiple threads initialize the same class, only one thread is allowed to initialize

Exploration of short text analysis in the field of medical and health (II)

Missile interception -- UPC winter vacation training match

如何搭建一支搞垮公司的技術團隊?

How to build a technical team that will bring down the company?

如何做一个炫酷的墨水屏电子钟?

Bert fine tuning skills experiment

R language uses logistic regression and afrima, ARIMA time series models to predict world population

Codeforces Global Round 19 ABC

Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
随机推荐
Application and Optimization Practice of redis in vivo push platform
Some query constructors in laravel (2)
Application and Optimization Practice of redis in vivo push platform
Include rake tasks in Gems - including rake tasks in gems
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
Three properties that a good homomorphic encryption should satisfy
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Application and development trend of image recognition technology
Runc hang causes the kubernetes node notready
Marubeni Baidu applet detailed configuration tutorial, approved.
Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
Win: enable and disable USB drives using group policy
Win: use PowerShell to check the strength of wireless signal
RichView TRVStyle MainRVStyle
Binary tree traversal - middle order traversal (golang)
What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
Naacl 2021 | contrastive learning sweeping text clustering task
Missile interception -- UPC winter vacation training match
Codeforces Global Round 19 ABC
One click generation and conversion of markdown directory to word format