Sync Code:
public static void ImportData()
{
for (var i = 0; i < 40000; i++)
{
DoSomething(i)
}
}
Async Code:
public static void ImportDataAsync()
{
for (int i = 0; i < 40000; i++)
{
await DoSomething(i)
}
}
Just to be clear, that's one of my first attempt in async operation.
With the async code, my software it's really slow, when if i run synchronously multiple instance of the command line application it's 10x time faster.
I mean, i don't think that the DB access and the try/catch block of the GetAsync
function will do this abissal difference between the two method, what do you think?
Edit: I don't know how to improve this question, but i will try to give an answer instead.
What i was asking is for the "Parallel.Foreach" method, what i was doing is thinking that the "await" prefix would set the current thread in standby creating another thread and continuing the for cycle, instead, what the await did is to simply leave that method until the awaited result, then he came back at the same point in the for cycle and resume it where he was awaiting.
I was just confusing things, specially in a Console Application actually i do not see any good reason to use await/async.