Tuesday, February 13, 2018

c# - How to use async in sync code?

Async method (works fine in async code):



public async Task> GetConfigAsync(string id)
{
var entity = await _entityRepo.FindAsync(t => t.Id == id);
if (entity == null) throw new Exception($"entity Id {id} is invalid");
var result = JsonConvert.DeserializeObject(entity.Config);
return new ServiceResult(result);

}


And I try to call it from sync code:



var configTask = _configurationService.GetConfigAsync(id);
var config = configTask.GetAwaiter().GetResult();


I can't see any issue, so it I just stuck.




What I do wrong?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...