Home > OS >  Asp.Net MVC 4 - Load two pages in same time
Asp.Net MVC 4 - Load two pages in same time

Time:01-17

I have a little problem ith this part of code. I want to load two pages without lock between them.

First page has a wait task (25sec).

Second has no wait taks.

When I run my web app and call this two pages, I have to wait the end of first page to get the second page.

My question, how to load these two pages fully asynchronously ?

Please kindly find my code below.

Many thanks for your help !

public class AsyncTestController : Controller
    {
        // GET: AsyncTest
        public async Task<ActionResult> Delay()
        {
            await Task.Run(() => Thread.Sleep(25000));
            return View();
        }
        // GET: AsyncTest
        public async Task<ActionResult> Index()
        {
            return View();
        }
    }

CodePudding user response:

Thanks for your answer. Maybe I was not clear on the issue.

I've two users, A and B.

User A is calling "Delay" pages. He has to wait 25 sec to get the result.

User B is calling "Index" just after User A. Normally he will get immedialty the callback. But in this case, he has to wait User A calback to get his page...

Why ?

CodePudding user response:

It is not recommended to load two pages at the same time in ASP.NET MVC 4. Each request to a server should be handled separately and in sequence. Loading multiple pages simultaneously can cause issues with server resources, data integrity, and user experience. Instead, you can use techniques such as AJAX calls and partial views to load dynamic content within a single page without disrupting the user experience.

  • Related