Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question