Skip to content

Instantly share code, notes, and snippets.

@kneerunjun
Last active April 27, 2016 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kneerunjun/2694b33243a7ba480d027ee32c774244 to your computer and use it in GitHub Desktop.
Save kneerunjun/2694b33243a7ba480d027ee32c774244 to your computer and use it in GitHub Desktop.
[RoutePrefix("some")]
public class SomeController :ApiController{
[HttpGet]
[Route("test")]
public IHttpActionResult Test(){
Repo repo = new Repo();
var task = repo.GetAll();
task.Wait(); //Im sure this was working in the previous versions but is not now.
var allEmps = task.Result; // here it gets lost and has no clue how to come back to this promise
return Ok<List<Employee>>(allEmps)
}
}
public class Repo {
public async Task<Employee> GetAll(){
//some task here and it woudl be asynchronous
}
}
public class Employee{
//a couple of properties here
}
[RoutePrefix("some")]
public class SomeController :ApiController{
[HttpGet]
[Route("test")]
public Task<IHttpActionResult> Test(){
Repo repo = new Repo();
return Ok<List<Employee>>(await repo.GetAll()); //and now since the action itself is async , this works
//very funny its either I have not understood threading in .NET or that MS has changed a few nuts and bolts underneath
}
}
public class Repo {
public async Task<Employee> GetAll(){
//some task here and it woudl be asynchronous
}
}
public class Employee{
//a couple of properties here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment