title: Call a Console App from ASP.NET MVC, but don't want to wait for the response
body: <p><strong>I am trying to achieve something like this.</strong></p>
  
  <pre><code>    private Process p;
  
      //
      // GET: /Home/
      [HttpGet]
      public ActionResult Index()
      {
          return View(new Contents() { Text = "Hello" });
      }
  
      [HttpPost]
      public ActionResult Processing()
      {
          // Get the file path of your Application (exe)
          string filePath = @"Z:\Junk\MVCtoConsole\Sample Console App\bin\Debug\Sample Console App.exe";
  
          ProcessStartInfo info = new ProcessStartInfo(filePath);
          info.RedirectStandardOutput = true;
          info.UseShellExecute = false;
  
          p = Process.Start(info);
          p.WaitForExit(1);
  
          Session["pid"] = p.Id;
  
          return View("Index", new Contents() { Text = "Processing" });
      }
  
      [HttpPost]
      public ActionResult Kill()
      {
          int pid = (int)Session["pid"];
  
          p = Process.GetProcessById(pid);
  
          p.Kill();
  
          return View("Index", new Contents() { Text = "Killed" });
      }
  
      public ActionResult Update()
      {
          int pid = (int)Session["pid"];
  
          p = Process.GetProcessById(pid);
  
          return View("Index", new Contents() { Text = p.StandardOutput.ReadToEnd() });
      }
  </code></pre>
  
  <p><strong>But I get the following errors when calling the update view...</strong></p>
  
  <blockquote>
    <p>Server Error in '/' Application.</p>
    
    <p>StandardOut has not been redirected or
    the process hasn't started yet.</p>
    
    <p>Description: An unhandled exception
    occurred during the execution of the
    current web request. Please review the
    stack trace for more information about
    the error and where it originated in
    the code. </p>
    
    <p>Exception Details:
    System.InvalidOperationException:
    StandardOut has not been redirected or
    the process hasn't started yet.</p>
    
    <p>Source Error: </p>
    
    <p>Line 56:             p =
    Process.GetProcessById(pid); Line 57: 
    Line 58:             return
    View("Index", new Contents() { Text =
    p.StandardOutput.ReadToEnd() }); Line
    59:         } Line 60:     }</p>
    
    <p>Source File:
    Z:\Junk\MVCtoConsole\MVCtoConsole\Controllers\HomeController.cs
    Line: 58 </p>
    
    <p>Stack Trace: </p>
    
    <p>[InvalidOperationException:
    StandardOut has not been redirected or
    the process hasn't started yet.]<br>
    System.Diagnostics.Process.get_StandardOutput()
    +1172937    MVCtoConsole.Controllers.HomeController.Update()
    in
    Z:\Junk\MVCtoConsole\MVCtoConsole\Controllers\HomeController.cs:58
    lambda_method(ExecutionScope ,
    ControllerBase , Object[] ) +40<br>
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
    controller, Object[] parameters) +17<br>
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
    controllerContext, IDictionary<code>2
    parameters) +178<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
    controllerContext, ActionDescriptor
    actionDescriptor, IDictionary</code>2
    parameters) +24<br>
    System.Web.Mvc.&lt;>c_<em>DisplayClassd.b</em>_a()
    +52    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
    filter, ActionExecutingContext
    preContext, Func<code>1 continuation) +254 
    System.Web.Mvc.&lt;&gt;c__DisplayClassf.&lt;InvokeActionMethodWithFilters&gt;b__c()
    +19    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
    controllerContext, IList</code>1 filters,
    ActionDescriptor actionDescriptor,
    IDictionary<code>2 parameters) +192<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
    controllerContext, String actionName)
    +314    System.Web.Mvc.Controller.ExecuteCore()
    +105    System.Web.Mvc.ControllerBase.Execute(RequestContext
    requestContext) +39<br>
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
    requestContext) +7<br>
    System.Web.Mvc.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__4()
    +34    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0()
    +21    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8</code>1.b__7(IAsyncResult
    _) +12    System.Web.Mvc.Async.WrappedAsyncResult`1.End()
    +59    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult
    asyncResult) +44<br>
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
    result) +7<br>
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    +8690318    System.Web.HttpApplication.ExecuteStep(IExecutionStep
    step, Boolean&amp; completedSynchronously)
    +155</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:2.0.50727.5446;
    ASP.NET Version:2.0.50727.5420</p>
  </blockquote>
  
  <p><strong>Any Ideas as to how this can be achieved?</strong></p>
  
  <p><strong>Oh my console app isn't doing very much just now, as I am just trying to find out if this will work.</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading;
  
  namespace Sample_Console_App
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("Triggered");
  
              for (int i = 0; i &lt; 100000; i = i + 100)
              {
                  Console.WriteLine(i);
                  Thread.Sleep(1000);
              }
          }
      }
  }
  </code></pre>