Tuesday, 13 February 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...