What does the suspend function mean in a Kotlin Coroutine?

I’m reading Kotlin Coroutine and know that it is based on suspend function. But what does suspend mean? Coroutine or function gets suspended? From https://kotlinlang.org/docs/reference/coroutines.html Basically, coroutines are computations that can be suspended without blocking a thread I heard people often say “suspend function”. But I think it is the coroutine who gets suspended because … Read more

Parallel foreach with asynchronous lambda

I would like to handle a collection in parallel, but I’m having trouble implementing it and I’m therefore hoping for some help. The trouble arises if I want to call a method marked async in C#, within the lambda of the parallel loop. For example: var bag = new ConcurrentBag<object>(); Parallel.ForEach(myCollection, async item => { … Read more

When should I use Async Controllers in ASP.NET MVC?

I have some concerns using async actions in ASP.NET MVC. When does it improve performance of my apps, and when does it not? Is it good to use async action everywhere in ASP.NET MVC? Regarding awaitable methods: shall I use async/await keywords when I want to query a database (via EF/NHibernate/other ORM)? How many times … Read more

await vs Task.Wait – Deadlock?

I don’t quite understand the difference between Task.Wait and await. I have something similar to the following functions in a ASP.NET WebAPI service: public class TestController : ApiController { public static async Task<string> Foo() { await Task.Delay(1).ConfigureAwait(false); return “”; } public async static Task<string> Bar() { return await Foo(); } public async static Task<string> Ros() … Read more

Call asynchronous method in constructor?

Summary: I would like to call an asynchronous method in a constructor. Is this possible? Details: I have a method called getwritings() that parses JSON data. Everything works fine if I just call getwritings() in an async method and put await to left of it. However , when I create a LongListView in my page … Read more

Calling async method synchronously

I have an async method: public async Task<string> GenerateCodeAsync() { string code = await GenerateCodeService.GenerateCodeAsync(); return code; } I need to call this method from a synchronous method. How can I do this without having to duplicate the GenerateCodeAsync method in order for this to work synchronously? Update Yet no reasonable solution found. However, I … Read more