StringBuilder
StringBuilder

Reputation: 1629

Long operation in MVC 4

I am trying to understand the proper way to perform the following task.

I have a long operation (Database insertion about 10000 rows) after user input. I need to return to a user some View that will say that his job is in progress , no need to show progress or something , but I can't freeze the ui for user.

public class AuthController : SurfaceController
    {
        public ActionResult LongOpeartion(UserInput model)
          {
              // Long async operation goes here 
              return View();
          }

    }

Can anyone please suggest the Right way of firing async Task , or something. Thanks.

Upvotes: 0

Views: 187

Answers (2)

Kailas Mane
Kailas Mane

Reputation: 1935

I think Asynchronous Controller will help you in this regards,

please check following link,

Asynchronous Controller in MVC

Upvotes: 1

gimpycpu
gimpycpu

Reputation: 607

Since you can't use ajax and want to reply right away I think this would be appropriate.

public class AuthController : SurfaceController
{
    public ActionResult LongOpeartion(UserInput model)
      {
         Task t = Task.Run( () => {
             // Long async operation goes here 
          } );

          return View();
      }

}

Upvotes: 1

Related Questions