1

I have an async function that pulls emails from Office365. The application will send emails with no difficulty using the graphServiceClient but when I ask for the inbox contents I end up with a blocking line when I await (ie the following line of code is never reached, 'messages' is never populated):

messages = Await graphClientService.Users(ID).MailFolders.Inbox.Messages.Request.GetAsync

I then rewrote synchronously and the call now works and does not block:

messages = graphClientService.Users(ID).MailFolders.Inbox.Messages.Request.GetAsync.GetAwaiter.GetResult

Everything I read says the latter is bad practice as it will block the thread in the event of a mishap - but the asynchronous call hangs the thread completely.

Am I missing something in my Async implementation? This feels like my naivety but days of googling has yielded nothing.

Rich Freeman
  • 1,009
  • 2
  • 9
  • 22
  • 2
    It feels like an exception is being thrown but because the call stack is not async "all the way down" the exception gets lost and weird stuff happens. Could you confirm whether all method calls in the call stack to this point are all async? – phuzi Nov 09 '21 at 10:07
  • Thank you - that put me on the right track - it seemed like I had both synchronous and async calls through GraphServiceClient and mixing the two was causing a problem. Reverting to everything being Async seems to have solved my problem - but I'm not sure it answers my question? – Rich Freeman Nov 09 '21 at 13:59
  • Been frustrated by this myself when mixing sync/async calls causing deadlocks. – phuzi Nov 09 '21 at 15:26

0 Answers0