C
C#2y ago
CrosRoad95

❔ Making an async method without anything to async inside

let's say i have following scenario:
void Foo()
{
for(int i = 0 ; i < 10000000 ;i++){} // simulate load
}
void Foo()
{
for(int i = 0 ; i < 10000000 ;i++){} // simulate load
}
the following method is blocking, but also don't have anything that can await inside. how can i turn this example into async Task Foo()?
3 Replies
CrosRoad95
CrosRoad95OP2y ago
seen some people were using Task.FromResult that i don't understand how it works at least i can run this task and maybe await later
async Task Foo()
{
await Task.Run(() => {
for(int i = 0 ; i < 10000000 ;i++){}
});
}
async Task Foo()
{
await Task.Run(() => {
for(int i = 0 ; i < 10000000 ;i++){}
});
}
is it okey to do like this? how? 😄 ^ but stacktrace will be wrong watched nick chapsas and he said returning a task without awaitng is not very good idea
mindhardt
mindhardt2y ago
Haven't really used but there is Parallel.For Maybe that will help if you want it to be parallel
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server