Getting the result from a list of tasks
Its been a minute since I have done async methods but i know i can do a list of tasks I just think I'm using them wrong.
I need to create a lot of points so i wanted to split it up to make it faster
13 Replies
so dies it return the value of all the tasks i have running?
because doing
var test = Task.WhenAll(tasks);
says test is just a task not a array of any sortThe value is in the individual task
Which, btw, create points async is synchronous
what am i doing wrong, i thought if it was async and you ran it on a task it ran in a different thread
Common misconception
You don't have any awaits in your async method, so it will just be synchronous
If you need to run CPU heavy code in a thread, use Task.Run
can i just add an await before the return?
If you added an await as the first line that would work. Just before the return... Nope
how do i do it your way, with just Task.Run
assume that is the way I'm supposed to do something like this
Change the create points method to just return a list of point, no async or task
tasks.Add(Task.Run(() => CreatePoints(i)));
?Yes
or am i not adding them to a list anymore either
ok cool
ok so its not giving me anything. like its not running at all since its finishes instantly
Look at your first for loop
ah yeah
that will do it