我在 Process.Start()
上遇到了困难
这是代码:
static void Main(string[] args)
{
string fileName = @"C:\path_to_project\bin\Debug\helloworld.exe";
ProcessStartInfo info = new ProcessStartInfo(fileName);
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.CreateNoWindow = true;
Process process = Process.Start(info);
string error = process.StandardError.ReadToEnd();
string returnvalue = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.ReadLine();
}
代码应该只调用 helloworld 控制台应用程序,该应用程序只有一行 Console.WriteLine("Hello World")
,没有什么特别的。
当我调试此代码时,我到达 Process process = Process.Start(info);
然后,当我点击“单步执行”(F10) 时,什么也没有发生。我的应用程序挂起,我启动的进程在那里,但尚未完成。我需要把他们全部杀掉。
这段代码可以在我同事的机器上运行,但在我的机器上,进程只是挂起,我唯一能做的就是终止该进程。
我还注意到,当我双击资源管理器中的任何控制台应用程序时,光标会将状态更改为忙碌,并且在我杀死 explorer.exe 之前不会变回原来的状态。
这可能是一些安全问题或恶意软件吗?
最佳答案
Avast Antivirus 拦截 Process.Start(),可能它会尝试对我尝试启动的应用程序进行沙箱处理,因此它会挂起。
我暂时禁用了防护罩,现在它可以工作了。
感谢大家的努力。
关于c# - Process.Start() 导致应用程序挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34352565/