Monday 30 December 2019

c# - How to take async result in getter?

I have a method in repository with this implementation which returns a Task


Task> GetAllAppsRequestAsync();

I write the getter which call this async method


public IList ApplicationsList
{
get
{
IList applicationDTO = _appService.GetAllAppsRequestAsync();
if (applicationDTO != null)
{
applicationList = mapper.DefaultContext.Mapper.Map>(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 func)
{
AsyncHelper._myTaskFactory
.StartNew(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> TakeAppListAsync()
{
IList applicationDTO = await _appService.GetAllAppsRequestAsync();
if (applicationDTO != null)
{
applicationList = mapper.DefaultContext.Mapper.Map>(applicationDTO);
}
return applicationList;
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...