[英]Start a c# console application when .NET MVC Application starts on Visual Studio
I'm looking to launch a console application that has to run parallel to my main .NET MVC Application, when the main app starts. 我希望启动一个控制台应用程序,该应用程序必须在主应用程序启动时与主.NET MVC应用程序并行运行。
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. 我的猜测是,这可以在我的MVC应用程序启动中的某个位置完成。
How can this be accomplished? 如何做到这一点?
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: 您可能希望托管Windows服务来执行此操作,但是如果您想要一种快速而肮脏的方式来执行此操作,则可以在线程中生成一个新进程:
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)
{
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.