Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
Hi,

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
Posted
Updated 15-Mar-16 8:01am

1 solution

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:
Quote:
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.
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900