Based on this answer, I have the following ASP.NET Action that's supposed to run a process asynchronously. However, when I make multiple parallel requests, each runs only after the previous one completes. Why does this happen?
public async Task<ActionResult> Index(string url)
{
var exePath = Server.MapPath("~/App_Data/dummy/bin/dummy.exe");
var startInfo = new ProcessStartInfo
{
FileName = exePath,
Arguments = url,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = new Process{ EnableRaisingEvents = true, StartInfo = startInfo};
var tcs = new TaskCompletionSource<Process>();
process.Exited += (sender, a) =>
{
tcs.SetResult(process);
};
process.Start();
await tcs.Task;
// todo: return process status/output
return View();
}
The code for dummy.exe
, the process called in the MVC Action, is:
class Program
{
static void Main(string[] args)
{
Thread.Sleep(5000);
Console.WriteLine("Hello world!");
}
}