Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 Ajax wait before executing the next process
    text
    copied!<p>In my MVC project I generate an array of images and store the array as a session variable, I animate the images using slidebar and by detecting mouse movement while mouse button is down by calculating the distance between the first click and x position while the mouse is moving on a canvas.</p> <p>In the controller I use:</p> <pre><code>public ActionResult Animate(int slice = 0, int udm = 0) { FileContentResult data; Image objImage = null; Bitmap im = null; try { im = MySession.Current.imageArray[slice]; .... MySession.Current.image = im; } else { return RedirectToAction("Index",new {.... }); } } catch { } return null; } </code></pre> <p>and</p> <pre><code> public ActionResult ImageOut(int udm = 0) { FileContentResult data; Image objImage = null; Bitmap im = null; im = MySession.Current.image; ... objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m); MemoryStream ms1 = new MemoryStream(); using (var memStream = new MemoryStream()) { objImage.Save(memStream, ImageFormat.Png); data = this.File(memStream.GetBuffer(), "image/png"); } objImage.Dispose(); return data; } </code></pre> <p>From the view I use Ajax:</p> <pre><code> $.ajax({ url: '/Home/Animate', type: 'POST', async: false, data: { slice: ((lastX - firstX) + nSlice), udm: ++udm }, success: function(data) { if (data.udm) { nSlice = (data.slice); image.src = '/Home/ImageOut?' + $.param({ udm: data.udm }); } }, error: function() { } }); </code></pre> <p>I have two problems, first it takes time to update the view and skips a number of images, the second is it open many threads and if a number of users accessing the same page it slows down. I thought of using async but I am still using c# 4 and this may requires lots of changes to my code. I was reading about SignalR, my question is can this be done (providing I just update the user screen not all users) or is there a better solution. </p> <p>The sequence of events I would like to achieve is:</p> <ol> <li>Ajax send to the first action a request or generate the first image and wait </li> <li>When the image is generated, Ajax receive success, then display the image on the screen using the second action</li> <li>Then the first action generate the second image </li> </ol> <p>The challenge I see is the first image keep generating the images without waiting, so my question is how I make the first action wait, and how to send to it a message to generate the following image.</p> <p>I just installed VS2012 c#5, is there any example that can help me!! Would appreciate your suggestions, thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload