Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I Have Two Menu Items in My Mvc Application, I want to Allow user to navigate second menu when he clicks while the current(first) action is getting executed, First action is asynchronous action but still its blocking user until it gets completed

What I have tried:

I blocked user not go into other action while current is getting executed but my requirement is I should allow the user to go into other pages while current one being executing
Posted
Updated 14-Mar-19 9:17am
v2

That's not quite how HTTP works. HTTP works on the Request AND Response. While you can navigate away from the original URL, any requests it made are likely to be canceled.

The best thing I could recommend is to have URL1 on the server just a "wrapper" which defines a task and then runs it. Once Task.Run() starts you can then return the proper response (should be 200: Accepted).
This should satisfy your AJAX request almost immediately so that the second link can be acted upon

Reference:
c# - Return before async Task complete - Stack Overflow[^]
 
Share this answer
 
This is a repost of your question, Display visual result of async process in MVC action[^]. The content from your comment helps in understanding the question.

The problem is that your tasks are asynchronous, meaning there is no information as to how much time it will take. Thus, it is a good practice to use a background service to keep a track of that task and you show the progress in the layout. This way, you will decouple the current page and the task.

You can utilize background threads to perform these actions. Thread pool threads are limited, and you will run out of threads quickly. Creating new threads is expensive and costly, and might not be a good solution at all. In this way, if I had to do this, I would consider using some sort of event-processing, like a message queue to manage and maintain the state of certain events and operations. Each operation can have its state, progress, and I can use that to update the users.

Check these links for a practical overview,
How to run Background Tasks in ASP.NET - Scott Hanselman[^]
c# - How to run long-lasting process asynchronously under asp.net? - Stack Overflow[^]
Simple Asynchronous Background Task Processing with Progress Dialog (Silverlight Solution)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900