0

I am building an MVC application that includes an asynchronous image upload so each image, once uploaded, calls the action. Image uploading can be cpu intensive and require time so we are trying to avoid in-action processing.

I have read about using async actions, but we are also processing images at other times, so we have opted to handle image processing through a console application.

What is the proper method for calling a console application from an MVC action asynchronously? Basically we just want to pass the console app some parameters, and tell it start without waiting for any kind of response from the console.

Our program file is an exe.

Speed is our main concern here.

Thanks so much for your help!

EDIT

As per Brian's suggestion here is what we added:

Process pcx = new System.Diagnostics.Process(); ProcessStartInfo pcix = new System.Diagnostics.ProcessStartInfo(); pcix.FileName = "C:\\utils_bin\\fileWebManager\\ppWebFileManager.exe"; pcix.Arguments = WrkGalId.ToString() + " " + websiteId.ToString() + "" + " " + "19" + " \"" + dFileName + "\" "; pcix.UseShellExecute = false; pcix.WindowStyle = ProcessWindowStyle.Hidden; pcx.StartInfo = pcix; pcx.Start(); 
2
  • 2
    I probably would not opt for executing a console application from a web app. I would instead opt for a windows service that watches for changes in your upload folder. Commented Feb 3, 2014 at 19:59
  • Thanks Brian! I was just looking at the FileSystemWatcher class to do just that but we may test the async controller option provided in MVC 4. Commented Feb 3, 2014 at 22:49

1 Answer 1

2

You would use Process.Start to execute an external application, e.g.:

Process.Start(@"C:\\path\to\my\application.exe"); 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Brian, I have added this and it is working but we are finding that there seems to be some kind of delay happening when the call to the app is made. It takes about 7 - 13 seconds longer per file upload when calling the app. Is this normal? I have added our code as an edit above.
You need to execute the process on a different (non IIS worker) thread, or use the task parallel library.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.