title: MVC4 Force session update before request ends
body: <p>We are developing using VS2010 and MVC4, deploying our web app on an IIS 7.5 on Windows7.</p>
  
  <p>Our project has a long running process for which we want to display status and progress.</p>
  
  <p>In order to accomplish this we have a small serializable class with properties that describe the current status. The long operation pseudo code goes like this:</p>
  
  <pre><code>int curentPercentComplete = 0;
  EngineStatus status = new EngineStatus();
  while (!done) {
      status.PercentComplete = curentPercentComplete;
      Session['status'] = status;
      // do lengthy operation
      curentPercentComplete = compute();
      done = isJobFinished();
  }
  </code></pre>
  
  <p>We also have an other controller action that tries to retrieve the current status from the session
  which then encodes to json and returns it to the browser via an Ajax request.</p>
  
  <p>Our problem is that we always seem to get the last saved data from the previous request, in other words the session object does not seem to update the Session['status'] field during the execution of the while block.</p>
  
  <p>We have tried the session state mode both InProc and StateServer with exactly the same behavior. </p>
  
  <p>Thanks in advance.</p>