c# - Process.Start() 继续运行我的 .exe 作为后台进程 MVC ASP.Net

标签 c# asp.net-mvc asp.net-mvc-4 process.start

<分区>

首先,我查看了网络以尝试找到答案,但我只遇到过想要在后台运行其进程的人,而我这里的问题恰恰相反。

我在我的 Controller 上输入了以下代码,单击按钮时启动了该过程:

string fileLocation = @"C:\somefolder\anotherFolder\...\application.exe";
        ProcessStartInfo oStartInfo = new ProcessStartInfo();
        oStartInfo.FileName = fileLocation;
        oStartInfo.UseShellExecute = false;
        oStartInfo.CreateNoWindow = true;
        oStartInfo.WindowStyle = ProcessWindowStyle.Normal;
        oStartInfo.CreateNoWindow = false;
        var process = new Process { StartInfo = oStartInfo, EnableRaisingEvents = true };
        process.Start();

现在我已经运行了代码,它正在执行 exe,或者当我打开任务管理器时它会出现。但我似乎无法让它在前台执行,因此用户可以做他们需要做的事情。

*额外信息

  • 每当我在运行后尝试重建时都会出现问题,因为 exe 与项目的 Web 部分在同一个解决方案中,但问题是我必须转到任务管理器并终止进程否则它无法访问 .exe——这是我需要在前台运行它的另一个主要原因

  • 适用于网络的 Visual Studio 2013 Express

  • Entity Framework
  • MVC Asp.Net 网络项目

任何帮助都会非常棒!

最佳答案

请看这里:Process.Start method :

ASP.NET Web page and server control code executes in the context of the ASP.NET worker process on the Web server. If you use the Start method in an ASP.NET Web page or server control, the new process executes on the Web server with restricted permissions. The process does not start in the same context as the client browser, and does not have access to the user desktop.

因此,该进程将在服务器端运行,而不是在客户端运行,并且还将在 ASP.Net 工作进程 (w3wp.exe) 的用户配置文件中运行,这意味着您不会看到进程窗口,除非您碰巧在同一个人资料中以交互方式登录。

关于c# - Process.Start() 继续运行我的 .exe 作为后台进程 MVC ASP.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28089683/

相关文章:

c# - Umbraco 7 和 Visual Studio 2013

asp.net-mvc-3 - MVC4 Razor 中可能存在重大变化,可通过 "@:@"修复

c# MainWindowHandle 始终为零

c# - 等待/异步奇怪的行为

c# - 如何在 C# 中调用特定的显式声明的接口(interface)方法

c# - linq toentity datediff 单元测试失败,但 sql 数据失败

asp.net-mvc - 如何在azure中关闭应用程序服务的一个实例

c# - 如何为路由注册区域

ASP.NET (MVC) - 将页面渲染到文件

jquery - ASP.NET MVC : The best way to return type to a AjaxRequest?