title: Retrieving process ID in controller from model
body: <p>I have made a file converter using FFmpeg in MVC, and am now trying to cancel a specific conversion process. I get the ID of the process in my Encoder class and try to retrieve it in the FileController. This, however, only gives 0. What is wrong, and how can I retrieve the ID in the controller?</p>
  
  <p><strong>UPDATED:</strong>
  The convert method in FileController is called by two buttons in the view, one for conversion (hidden and starts automatically) and one for cancel. I tried to save the encoder object in a session in Global.asax and then retrieve them again for the conversion and the cancel. This works, but as I added the session, when I try to cancel the process by clicking the button, nothing happens until the convert method is all done. It then starts again (as if it has been in a queue) and goes to the cancel method. Previously to the session, the cancel button would interupt the method.</p>
  
  <p>What can I do to make the cancel button interupt the conversion method?</p>
  
  <pre><code>    //Encoder class
      private string RunProcess(string Parameters, string fileType) {
      //...
      ProcessStartInfo oInfo = new ProcessStartInfo(this.FFmpegPath, Parameters);
      Process proc = System.Diagnostics.Process.Start(oInfo);
      _ID = proc.Id;
      //... }
  
      private int _ID;
      public int Id {
          get { return _ID; }
          set { _ID = value; }
      }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>    //FileController
  
      [HttpPost]
      public ActionResult Convert(String id, string convert, string kill, string test) {
      //...
      Encoder obj = Session["Encoder"] as Encoder;
      if (convert != null) {
      EncodedVideo encoded = obj.EncodeVideo(inputv, 
      QuickVideoEncodingCommands.Mpeg, outputVPath, true, ext); //Starts encoding
      //...
      } else {
      return KillProcess();
      }}
  
      public ActionResult KillProcess() {
      Encoder obj = Session["Encoder"] as Encoder;
      int id = obj.Id;
      Process p = Process.GetProcessById(id);
      p.Kill();
      //... }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>    //Global.asax
      protected void Session_Start() {
          HttpContext.Current.Session["Encoder"] = new Encoder();
      }
  </code></pre>