Click here to Skip to main content
14,366,152 members
Rate this:
Please Sign up or sign in to vote.

I know the internet is littered with fragments of information on this subject, but none of them seems to provide a clear explanation of how you incorporate async functions into synchronous code.

I seem to be caught between a rock and a hard place. I have to call an API that provides only an async function, but this is called from a framework that provides only a synchronous function where I can call from. Therefore, it doesn't matter how far I propagate async keywords through my own code, sooner or later I bump into the problem of calling an async method from synchronous code.

More generally, I must be doing something wrong with this stuff. The async/await keywords are supposed to simplify parallel programming. I am finding the exact opposite. I've done parallel programming in C, C++ and now C# (using the TPL), and I have to say that I have never had so many problems as I am having now.

What am I missing?

Kind wishes ~ Patrick

What I have tried:

I'm tempted to say I have tried everything, but that's not enough characters for this box.

Sorry for the vagueness of the question, but I'm really struggling to find clear explanations of how to use asynch
Updated 15-Mar-16 9:01am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Here is a good article by Stephen Cleary:
Async/Await - Best Practices in Asynchronous Programming[^]

But I'm afraid he says what you don't want to hear:
As you convert synchronous code to asynchronous code, you’ll find that it works best if asynchronous code calls and is called by other asynchronous code—all the way down (or “up,” if you prefer). Others have also noticed the spreading behavior of asynchronous programming and have called it “contagious” or compared it to a zombie virus.
Patrick Skelton 16-Mar-16 13:21pm
That is indeed a great article. It also lead me to find the Channel 9 stuff, which is an excellent introduction to the most common pitfalls of using async/await. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100