0

I'm looking to launch a console application that has to run parallel to my main .NET MVC Application, when the main app starts.

It is a Console Application that keeps running until I manually quit the process.

My guess is that this can be done somewhere on the Start Up of my MVC application.

How can this be accomplished?

mason
  • 31,774
  • 10
  • 77
  • 121
Jorge Cuevas
  • 755
  • 3
  • 10
  • 30
  • 1
    Possible duplicate of [Running multiple projects in visual studio](http://stackoverflow.com/questions/16546307/running-multiple-projects-in-visual-studio) – mason Mar 23 '17 at 19:39
  • Also see [this duplicate](http://stackoverflow.com/questions/3850019/running-two-projects-at-once-in-visual-studio). – mason Mar 23 '17 at 19:39
  • When you say ` run parallel to my main .NET MVC Application`, do you mean in the same process or as a separate process? – Vikhram Mar 23 '17 at 19:44
  • Those are not duplicates, the user never specified if he wants his application to do this vs visual studio – johnny 5 Mar 23 '17 at 19:45
  • @johnny5 is right, I need to do this when the application is ran outside of visual studio. – Jorge Cuevas Mar 23 '17 at 19:48
  • Possible duplicate of [Calling an asp.net console application from my asp.net mvc web application](http://stackoverflow.com/questions/34757126/calling-an-asp-net-console-application-from-my-asp-net-mvc-web-application) – Joe C Mar 23 '17 at 19:56

1 Answers1

1

You probably want to host a windows service to do this, but if you want a quick and dirty way to do so you can spawn a new process in a thread:

 var t = Task.Run(() => {
     Process myProcess = new Process();

     try
     {
         myProcess.StartInfo.UseShellExecute = false;
         // You can start any process, HelloWorld is a do-nothing example.
         myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
         myProcess.StartInfo.CreateNoWindow = true;
         myProcess.Start();
     }
     catch(Exception ex)
     {
     }
 });
johnny 5
  • 19,893
  • 50
  • 121
  • 195