0

I have an action method which runs when a user submits a form.

An image URL is passed with the model.

I want to be able to perform some processing on the (downloaded) image, but i don't want a delay in this processing to affect the user experience.

so how can i do this processing in the background whilst happily submitting the form? e.g.:

ProcessImage(imageUrl); //do this in the background without delaying user experience  
abatishchev
  • 98,240
  • 88
  • 296
  • 433
raklos
  • 28,027
  • 60
  • 183
  • 301

3 Answers3

0

Until you are receiving the Image you cant change the user's page .

However after you gt the image you can do the required processing in BackGroundWorker and submit the page. And let the user see new required Page.

Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
  • can this be done as an asynchronous method? the completion of this method isnt relevant for the user. i just want this image processing to take place at some point after a user has submited the form. – raklos Feb 04 '11 at 16:37
  • BackgroundWorker is specially made for Asynchronous operation. You might use Threading but Backgroundworker is easy way to manage cross thread data transfers. Look at this answer on how to use it.. http://stackoverflow.com/questions/3527759/is-background-worker-a-thread-c/3527808#3527808 – Shekhar_Pro Feb 04 '11 at 21:40
0

Show a busy screen on the client that lets the user know that he's waiting for a file download. You could achieve this i.e. by downloading to a separate iframe and checking the status of the iframe (for a dynamic approach see Dynamically created iframe used to download file triggers onload with firebug but not without)

Community
  • 1
  • 1
safi
  • 3,636
  • 8
  • 24
  • 37
0

You can use jQuery to post the imageurl. Your callback will be called when it's done.

function ProcessImageUrl(imgurl) 
{ 
   $.post('<%= Url.Action("AjaxProcessImage","AjaxFunctions") %>'
      , { url: imgurl }
      , function (data) {
         if (data.success) {
           alert("I'm done processing the image");
         }
         else {
            alert("Darn an error occurred: " + data.msg);
         }
   });
}

In a controller called AjaxFunctionsController

   public ActionResult AjaxProcessImage(string url)
   {
      try
      {
          ProcessImage(url);
      }
      catch(System.Exception ex)
      {
         return Json(
               new
               {
                  success = false,
                  msg = ex.Message
               });
       }

      return Json(
            new
            {
               success = true
            });
   }
Craig Howard
  • 1,649
  • 15
  • 10