c# - Process.Start() 导致应用程序挂起

标签 c# .net console-application

我在 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/

相关文章:

c# - 使文本 block 的宽度自动

c# - 我可以访问我刚在 C# 中创建的 HTML 控件的高度/宽度吗?

c# - 添加时循环列表

c# - 为什么我在使用 SetPixel : SetPixel is not supported for images with indexed pixel formats? 时出现异常

c# - 编译查询和普通查询,对我 Entity Framework 来说似乎没有区别

C# - 从派生类中隐藏 UserControl 类的所有方法

c# - 文本转语音可以在 Windows Azure 上运行吗?

.net - WPF的标签云控制

c# - 访问其他服务器时登录失败: unknown user name or bad password.错误

c# - 将事件发送到独立应用程序