S
S
sanphir2017-09-20 12:13:53
.NET
sanphir, 2017-09-20 12:13:53

Why can await not await?

Hello.
I came across a strange behavior when using async await, the execution of the code just breaks.
Does not continue either synchronously or asynchronously. Exception'ov does not occur. Example:

public async Task<IEnumerable<MailChimpUser>> GetAllMembersAsync(string listName)
 {
  try
  {
   //Обрывается после выполнения этой строчки
   var list = await GetListByName(listName);
   
   //Причем если вместо вызова "расскрыть метод", так 
   //var lists = await _apiManager.Lists.GetAllAsync().ConfigureAwait(false);
   //list = lists.FirstOrDefault(l => l.Name == name);
   //то выполнение продолжится

   var members = await _apiManager.Members.GetAllAsync(list.Id).ConfigureAwait(false);

   var result = members.Select(m => new MailChimpUser()
   {
      ...
   });
   //то же самое здесь, после return не возвращается в метод где его эвэйтят...
   return result;
  }
  catch (Exception ex)
  {
   var logger = LogManager.GetCurrentClassLogger();

  logger.Error(ex, ex.Message, new object[] { });
    throw ex;
  }
 }

 private async Task<MailChimp.Net.Models.List> GetListByName(string name)
 {
  try
  {
    var lists = await _apiManager.Lists.GetAllAsync().ConfigureAwait(false);
    var list = lists.FirstOrDefault(l => l.Name == name);

    if (list == null)
      throw new Exception(String.Format("MailChimp: List \"{0}\" not found", name));
    return list;
  }
  catch (Exception ex)
  {
    var logger = LogManager.GetCurrentClassLogger();

    logger.Error(ex, ex.Message, new object[] { });
    throw ex;
  }
}

Tell me what's wrong and how can I fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mpnj, 2017-09-20
@sanphir

you need it like this:
var list = await GetListByName(listName) .ConfigureAwait(false) ;
Actually, when you "revealed", you did not forget to write .ConfigureAwait(false)
It is worth reading about ConfigureAwait and all sorts of deadlocks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question