Share via


HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete with partail view

Question

Monday, March 23, 2015 10:02 AM

Hello ,

 I have a partial view i'm trying to use and i'm getting this error ,

I assume the error is because i'm trying to use it with async with partailView.

is there  a way to do it ? or partailview are not to for async ?

public async Task<PartialViewResult> PiPic()
        {
            
            var results = await db.pictures.Where(c=>c.ToUpBanner==true). ToListAsync();
            if (results.Count() == 1)
            {
                return PartialView(results);
            }
            else
            {
                var mResults=await db.pictures.Where(c=>c.ToUpBanner==true). ToListAsync();
                   return PartialView(mResults);
            }

        }

@{Html.RenderAction("_PiPic", "Home");}

And the partial :
@model IEnumerable<_22_3_15.Models.Picture>

      @foreach (var item in Model.Skip(1))
                {
                    <img src="@item.PicUrl" class=" img-thumbnail img-responsive">
                }

All replies (4)

Monday, March 23, 2015 10:57 AM ✅Answered

or move the async query to the main controller action, where it can run at at the same time as other async operations, and make the request faster for the client.

note: using async tasks in the controller action allows more scaling, as the thread is returned to the pool while the async operation is running, but unless you overlap async operations, it no faster for the client. so calling controller action from the view prevents this overlap and makes the site slower.


Tuesday, March 24, 2015 3:48 AM ✅Answered

Hi,

I think the child action is not supported asynchronous in MVC 5 and previous version, please check this user voice below:

# Support asynchronous child actions

https://aspnet.uservoice.com/forums/41201-asp-net-mvc/suggestions/3233329-support-asynchronous-child-actions

In the next version, it has the new feature of view components that could achieve that.

# View components and Inject in ASP.NET MVC 6

http://www.asp.net/vnext/overview/aspnet-vnext/vc

So, you need to use normal child action in your project.

Regards

Starain


Monday, March 23, 2015 10:37 AM

I believe that Task Async for PartialView still persist some problems for MVC5 but it will be resolved for MVC6 using convention @await Component.InvokeAsync("yourcomponent") directives in your partial views. It is not threadsafe yet to use async for partial view but safe when rendering just plain views.

You are better off with client ajax call to load images for your partial views.


Monday, March 23, 2015 11:09 AM

 Hello  bruce , thanks for your answer

bruce (sqlwork.com)

or move the async query to the main controller action, where it can run at at the same time as other async operations, and make the request faster for the client.

<div paragraphname="paragraph0">,can you expand a bit more ?  I'm not sure I understand</div> <div paragraphname="paragraph0">

bruce (sqlwork.com)

note: using async tasks in the controller action allows more scaling, as the thread is returned to the pool while the async operation is running, but unless you overlap async operations, it no faster for the client. so calling controller action from the view prevents this overlap and makes the site slower.

</div> <div paragraphname="paragraph0"></div> <div paragraphname="paragraph0">So, you do you recommend using partial view without async  for faster site ?</div>