The ReserveAHolliday method cannot be made synchronous if you use the wait keyword in it.
What might be possible is to simply block until both async methods return their value. I do not recommend this because it can lead to deadlocks or other unforeseen errors.
If you don’t have a synchronization context (like a console application), you can simply write
bool hotelOK = ReserveAHotel().Result;
But I believe that you ultimately want to create a graphical interface. This is where blocking falls apart. Because the user interface application (Forms and WPF) has context and expects asynchronous methods to cause deadlocks. More here
There are workarounds for this problem, but they are highly dependent on the design of your application.
Edit:
If your library code needs a synchronization context, then locking is likely to cause a deadlock.
If you do not need this, it is possible to use ConfigureAwait(false) in your library code and exit with a lock.
What I recommend: async / await completely or not async / await at all. There are other possibilities to make your code asynchronous, for example: based on events, but, like everything else in life, have their pros and cons.
Read this blog post from Stephen Cleary. He explains why blocking asynchronous code will be inhibited and how you can avoid it.
source share