Skip to main content
added 4 characters in body
Source Link
dcastro
  • 69.1k
  • 22
  • 150
  • 158

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection .Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.TaskSystem.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail> to target type `System.Collections.Generic.IEnumerableSystem.Collections.Generic.IEnumerable<ThingDetail>

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection .Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task to target type `System.Collections.Generic.IEnumerable

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection .Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail> to target type System.Collections.Generic.IEnumerable<ThingDetail>

Where am I going wrong here?

added 21 characters in body
Source Link
Ehsan Sajjad
  • 62.6k
  • 16
  • 112
  • 171

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

 public async Task<JsonResult> GetLotsOfStuff()  {  IEnumerable<ThingDetail> things= {previouslyInitialisedCollection IEnumerable<ThingDetail> things= previouslyInitialisedCollection .Select(async q => await GetDetailAboutTheThing(q.Id)));   return Json(result, JsonRequestBehavior.AllowGet);  } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail>> to target type System.Collections.Generic.IEnumerable<ThingDetail>

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task to target type `System.Collections.Generic.IEnumerable

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

 public async Task<JsonResult> GetLotsOfStuff()   { IEnumerable<ThingDetail> things= previouslyInitialisedCollection.Select(async q => await GetDetailAboutTheThing(q.Id)));   return Json(result, JsonRequestBehavior.AllowGet);  } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail>> to target type System.Collections.Generic.IEnumerable<ThingDetail>

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

public async Task<JsonResult> GetLotsOfStuff() {  IEnumerable<ThingDetail> things= previouslyInitialisedCollection  .Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task to target type `System.Collections.Generic.IEnumerable

Where am I going wrong here?

fix formatting
Source Link
Grundy
  • 13.4k
  • 3
  • 39
  • 57

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

 public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection.Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task>'System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail>> to target type 'System.Collections.Generic.IEnumerable'System.Collections.Generic.IEnumerable<ThingDetail>

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

 public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection.Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task>' to target type 'System.Collections.Generic.IEnumerable'

Where am I going wrong here?

I have a method which is Async "upstream". I'm trying to follow best practice and go all-in qith async all the way up the stack.

Within a Controller action within MVC I predictably hit the deadlock issue If I rely on .Result().

Changing the Controller action to async seems to be the way to go, though the issue is that the async method is called multiple times within a lambda.

How can I await on a lamda that returns multiple results?

 public async Task<JsonResult> GetLotsOfStuff() { IEnumerable<ThingDetail> things= previouslyInitialisedCollection.Select(async q => await GetDetailAboutTheThing(q.Id))); return Json(result, JsonRequestBehavior.AllowGet); } 

You can see I have tried making the lambda async, but this just gives a compiler exception:

Cannot convert source type

System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<ThingDetail>> to target type System.Collections.Generic.IEnumerable<ThingDetail>

Where am I going wrong here?

Source Link
Program.X
  • 7.4k
  • 12
  • 53
  • 86
Loading