I have a method in repository with this implementation which returns a Task
Task<IList<ApplicationDTO>> GetAllAppsRequestAsync();
I write the getter which call this async method
public IList<ApplicationPropertyModel> ApplicationsList
{
get
{
IList<ApplicationDTO> applicationDTO = _appService.GetAllAppsRequestAsync();
if (applicationDTO != null)
{
applicationList = mapper.DefaultContext.Mapper.Map<IList<ApplicationPropertyModel>>(applicationDTO);
}
return applicationList;
}
set => Set(ref applicationList, value);
}
_appService.GetAllAppsRequestAsync();
- return task, and proble that getter doesn't have async
I try to write delegate, i take the problem when i map the models.
I try to find something but whatever I do, I take deathlock or don't wait my task with result.(try getAwaiter, wait,some example with wrapping) and doesn't know what to do?
forget i try to it by this
public static void RunSync(Func<Task> func)
{
AsyncHelper._myTaskFactory
.StartNew<Task>(func)
.Unwrap()
.GetAwaiter()
.GetResult();
}
but doesn't take the result, before project will finish
Node
I should use the property because it binding with with my itemControl in wpr xaml page.
Edit
private async Task<IList<ApplicationPropertyModel>> TakeAppListAsync()
{
IList<ApplicationDTO> applicationDTO = await _appService.GetAllAppsRequestAsync();
if (applicationDTO != null)
{
applicationList = mapper.DefaultContext.Mapper.Map<IList<ApplicationPropertyModel>>(applicationDTO);
}
return applicationList;
}